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)
| 1102 | |
| 1103 | |
| 1104 | def _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 | |
| 1124 | def _visible_width(s): |
no outgoing calls