glusto.colorfiable module

All things ANSI color text output.

Note

Colorfiable is inherited by the Glusto class and not designed to be instantiated.

class glusto.colorfiable.Colorfiable

Bases: object

Defines and displays ANSI-compatible colors for string formatting.

BG_DEFAULT = 1
BG_BLACK = 2
BG_RED = 4
BG_GREEN = 8
BG_YELLOW = 16
BG_BLUE = 32
BG_MAGENTA = 64
BG_CYAN = 128
BG_LTGRAY = 256
BG_DKGRAY = 512
BG_LTRED = 1024
BG_LTGREEN = 2048
BG_LTYELLOW = 4096
BG_LTBLUE = 8192
BG_LTMAGENTA = 16384
BG_LTCYAN = 32768
BG_WHITE = 65536
DEFAULT = 131072
BLACK = 262144
RED = 524288
GREEN = 1048576
YELLOW = 2097152
BLUE = 4194304
MAGENTA = 8388608
CYAN = 16777216
LTGRAY = 33554432
DKGRAY = 67108864
LTRED = 134217728
LTGREEN = 268435456
LTYELLOW = 536870912
LTBLUE = 1073741824
LTMAGENTA = 2147483648
LTCYAN = 4294967296
WHITE = 8589934592
NORMAL = 0
BOLD = 17179869184
DIM = 34359738368
UNDERLINE = 68719476736
REVERSE = 274877906944
HIDDEN = 549755813888
COLOR_COMMAND = 17246978048

Constant for command strings (BOLD | DKGRAY)

COLOR_STDOUT = 17180131584

Constant for stdout (BOLD | BG_LTGRAY | BLACK)

COLOR_STDERR = 17180393472

Constant for stderr (BOLD | RED)

COLOR_RCODE = 17184063488

Constant for command return code (BOLD | BLUE)

classmethod colorfy(color, message)

Applies ANSI terminal colors and attributes to strings.

Parameters:
  • color (int) – Bitwise value(s) for color settings.
  • message (str) – String to wrap in the specified color.
Returns:

A color formatted string.

Example

>>> g.colorfy(g.BG_CYAN | g.RED | g.BOLD, 'Bold red text on cyan')