luma.core.ansi_color

ANSI Escape-code parser

New in version 0.5.5.

luma.core.ansi_color.find_directives(text, klass)[source]

Find directives on class klass in string text.

Returns list of (method, args) tuples.

New in version 0.9.0.

Parameters:

text (str) – String containing directives.

Return type:

list

luma.core.ansi_color.parse_str(text)[source]

Given a string of characters, for each normal ASCII character, yields a directive consisting of a ‘putch’ instruction followed by the character itself.

If a valid ANSI escape sequence is detected within the string, the supported codes are translated into directives. For example \033[42m would emit a directive of ["background_color", "green"].

Note that unrecognised escape sequences are silently ignored: Only reset, reverse colours and 8 foreground and background colours are supported.

It is up to the consumer to interpret the directives and update its state accordingly.

Parameters:

text (str) – An ASCII string which may or may not include valid ANSI Color escape codes.

luma.core.ansi_color.strip_ansi_codes(text)[source]

Remove ANSI color codes from the string text.

New in version 0.9.0.

Parameters:

text (str) – String containing ANSI color codes.

Return type:

str