Onionr/src/onionrutils/escapeansi.py

13 lines
411 B
Python
Raw Normal View History

import re
2020-04-04 07:21:28 +00:00
def escape_ANSI(line):
'''
Remove ANSI escape codes from a string with regex
2019-06-26 20:13:36 +00:00
adapted from: https://stackoverflow.com/a/38662876 by user https://stackoverflow.com/users/802365/%c3%89douard-lopez
cc-by-sa-3 license https://creativecommons.org/licenses/by-sa/3.0/
'''
ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
2019-08-09 20:41:27 +00:00
return ansi_escape.sub('', line)