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 stringtext
.Returns list of
(method, args)
tuples.New in version 0.9.0.
- 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.