stouputils.print.utils module#
- remove_colors(text: str) str[source]#
Remove the colors from a text. See
remove_ansi()to remove all ANSI escape sequences>>> remove_colors("\x1b[91mHello\x1b[0m") 'Hello' >>> remove_colors("\x1b[1m\x1b[95mBold Magenta Text\x1b[0m") 'Bold Magenta Text' >>> remove_colors("No colors here") 'No colors here' >>> remove_colors("\x1b[91mRed\x1b[0m and \x1b[92mGreen\x1b[0m") 'Red and Green'
Other ANSI escape codes (e.g., cursor movement) are not removed since they are not colors: >>> remove_colors(“Line 1x1b[1ALine 2 x1b[31mRed Textx1b[0m”) ‘Line 1x1b[1ALine 2 Red Text’
- remove_ansi(
- text: str,
- pattern: str = '\\x1b\\[[0-?]*[ -/]*[@-~]',
Remove all ANSI escape sequences from a text. See
remove_colors()to remove only color codes.>>> remove_ansi("\x1b[91mHello\x1b[0m") 'Hello' >>> remove_ansi("\x1b[1m\x1b[95mBold Magenta Text\x1b[0m") 'Bold Magenta Text' >>> remove_ansi("No ANSI here") 'No ANSI here' >>> remove_ansi("\x1b[91mRed\x1b[0m and \x1b[92mGreen\x1b[0m") 'Red and Green' >>> remove_ansi("Line 1\x1b[1ALine 2") 'Line 1Line 2' >>> remove_ansi("Hello\x1b[2JWorld") 'HelloWorld'