MCPcopy Create free account
hub / github.com/astanin/python-tabulate / _strip_ansi

Function _strip_ansi

tabulate/__init__.py:1104–1121  ·  view source on GitHub ↗

r"""Remove ANSI escape sequences, both CSI (color codes, etc) and OSC hyperlinks. CSI sequences are simply removed from the output, while OSC hyperlinks are replaced with the link text. Note: it may be desirable to show the URI instead but this is not supported. >>> repr(_strip_ans

(s)

Source from the content-addressed store, hash-verified

1102
1103
1104def _strip_ansi(s):
1105 r"""Remove ANSI escape sequences, both CSI (color codes, etc) and OSC hyperlinks.
1106
1107 CSI sequences are simply removed from the output, while OSC hyperlinks are replaced
1108 with the link text. Note: it may be desirable to show the URI instead but this is not
1109 supported.
1110
1111 >>> repr(_strip_ansi('\x1B]8;;https://example.com\x1B\\This is a link\x1B]8;;\x1B\\'))
1112 "'This is a link'"
1113
1114 >>> repr(_strip_ansi('\x1b[31mred\x1b[0m text'))
1115 "'red text'"
1116
1117 """
1118 if isinstance(s, str):
1119 return _ansi_codes.sub(r"\4", s)
1120 else: # a bytestring
1121 return _ansi_codes_bytes.sub(r"\4", s)
1122
1123
1124def _visible_width(s):

Callers 7

_typeFunction · 0.85
_visible_widthFunction · 0.85
_formatFunction · 0.85
_lenMethod · 0.85
_handle_long_wordMethod · 0.85

Calls

no outgoing calls

Tested by 1