Created
November 11, 2021 17:53
-
-
Save dnbaker/75da10314d639e37e0faa96bcabab448 to your computer and use it in GitHub Desktop.
De-color text - especially useful for R tbl output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decolor(x): | |
from re import compile | |
return compile(r''' | |
\x1B # ESC | |
(?: # 7-bit C1 Fe (except CSI) | |
[@-Z\\-_] | |
| # or [ for CSI, followed by a control sequence | |
\[ | |
[0-?]* # Parameter bytes | |
[ -/]* # Intermediate bytes | |
[@-~] # Final byte | |
) | |
''', re.VERBOSE).sub('', x) | |
__all__ = ["decolor"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment