plainbox.impl.color – ANSI color codes

class plainbox.impl.color.Colorizer(color=None)[source]

Bases: builtins.object

Colorizing helper for various kinds of content we need to handle

BLACK(text, bright=True)[source]
BLUE(text, bright=True)[source]
CYAN(text, bright=True)[source]
GREEN(text, bright=True)[source]
MAGENTA(text, bright=True)[source]
RED(text, bright=True)[source]
WHITE(text, bright=True)[source]
YELLOW(text, bright=True)[source]
b(color_name)[source]
custom(text, ansi_code)[source]

Render a piece of text with custom ANSI styling sequence

Parameters:
  • text – The text to stylize
  • ansi_code – A string containing ANSI escape sequence to use.
Returns:

A combination of ansi_code, text and a fixed reset sequence that resets text styles.

Note

When the colorizer is not really doing anything (see is_enabled()) then custom text is not used at all. This is done to ensure that any custom styling is not permantently enabled if colors are to be disabled.

f(color_name)[source]
header(text, color_name='WHITE', bright=True, fill='=')[source]
is_enabled[source]

if true, this colorizer is actually using colors

This property is useful to let applications customize their behavior if they know color support is desired and enabled.

result(result)[source]
s(style_name)[source]
class plainbox.impl.color.ansi_off[source]

Bases: builtins.object

class b[source]

Bases: builtins.object

BLACK = ''
BLUE = ''
CYAN = ''
GREEN = ''
MAGENTA = ''
RED = ''
RESET = ''
WHITE = ''
YELLOW = ''
class ansi_off.f[source]

Bases: builtins.object

BLACK = ''
BLUE = ''
CYAN = ''
GREEN = ''
MAGENTA = ''
RED = ''
RESET = ''
WHITE = ''
YELLOW = ''
class ansi_off.s[source]

Bases: builtins.object

BRIGHT = ''
DIM = ''
NORMAL = ''
RESET_ALL = ''
class plainbox.impl.color.ansi_on[source]

Bases: builtins.object

ANSI control codes for various useful stuff. Reference source: wikipedia

class b[source]

Bases: builtins.object

Background color attributes

BLACK = '\x1b[40m'
BLUE = '\x1b[44m'
CYAN = '\x1b[46m'
GREEN = '\x1b[42m'
MAGENTA = '\x1b[45m'
RED = '\x1b[41m'
RESET = '\x1b[49m'
WHITE = '\x1b[47m'
YELLOW = '\x1b[44m'
class ansi_on.f[source]

Bases: builtins.object

Foreground color attributes

BLACK = '\x1b[30m'
BLUE = '\x1b[34m'
CYAN = '\x1b[36m'
GREEN = '\x1b[32m'
MAGENTA = '\x1b[35m'
RED = '\x1b[31m'
RESET = '\x1b[39m'
WHITE = '\x1b[37m'
YELLOW = '\x1b[33m'
class ansi_on.s[source]

Bases: builtins.object

Style attributes

BRIGHT = '\x1b[1m'
DIM = '\x1b[2m'
NORMAL = '\x1b[22m'
RESET_ALL = '\x1b[0m'
plainbox.impl.color.get_color_for_tty(stream=None)[source]

Get ansi_on if stdout is a tty, ansi_off otherwise.

Parameters:stream – Alternate stream to use (sys.stdout by default)
Returns:ansi_on or ansi_off, depending on if the stream being a tty or not.
plainbox.impl.color.obj_off

alias of s

plainbox.impl.color.obj_on

alias of s

Previous topic

plainbox.impl.clitools – support code for command line utilities

Next topic

plainbox.impl.commands – shared code for plainbox sub-commands

This Page