Control Sequences

Control sequences as per ECMA-48.

class todd.loggers.control_sequences.SGR[source]

Bases: IntEnum

Part of the SGR values.

BACKGROUND_BLACK = 40
BACKGROUND_BLUE = 44
BACKGROUND_CYAN = 46
BACKGROUND_GREEN = 42
BACKGROUND_MAGENTA = 45
BACKGROUND_RED = 41
BACKGROUND_WHITE = 47
BACKGROUND_YELLOW = 43
BOLD = 1
CONCEALED_CHARACTERS = 8
CROSSED_OUT = 9
DEFAULT = 0
DISPLAY_BLACK = 30
DISPLAY_BLUE = 34
DISPLAY_CYAN = 36
DISPLAY_GREEN = 32
DISPLAY_MAGENTA = 35
DISPLAY_RED = 31
DISPLAY_WHITE = 37
DISPLAY_YELLOW = 33
FAINT = 2
ITALICIZED = 3
NEGATIVE_IMAGE = 7
RAPIDLY_BLINKING = 6
SINGLY_UNDERLINED = 4
SLOWLY_BLINKING = 5
__new__(value)
todd.loggers.control_sequences.apply_sgr(str_, *parameter_bytes)[source]

Apply SGR to a string.

Parameters:
  • str – The string to apply SGR to.

  • parameter_bytes (SGR) – The SGR parameters.

  • str_ (str)

Returns:

The string with the SGR applied.

Return type:

str

Examples

>>> apply_sgr(
...     ' hello ',
...     SGR.BOLD,
...     SGR.DISPLAY_GREEN,
...     SGR.BACKGROUND_GREEN,
... )
'\x1b[1;32;42m hello \x1b[m'
todd.loggers.control_sequences.control_sequence(parameter_bytes, intermediate_bytes, final_byte)[source]
Parameters:
Return type:

str

todd.loggers.control_sequences.sgr(parameter_bytes)[source]
Parameters:

parameter_bytes (Iterable[SGR])

Return type:

str