Color

Colors module.

class cumin.color.ColoredType(name, bases, namespace, **kwargs)[source]

Bases: ABCMeta

Metaclass to define a new type that dynamically adds static methods to its classes.

COLORS = {'blue': 34, 'cyan': 36, 'green': 32, 'red': 31, 'yellow': 33}

a mapping of colors to the ANSI foreground color code.

Type:

dict

class cumin.color.Colored[source]

Bases: object

Class to manage colored output.

Available methods are dynamically added based on the keys of the ColoredType.COLORS dictionary. For each color a method with the color name is available to color any object with that specific color code.

Examples:

Colored.green(object)
disabled = False

switch to globally control the coloring. Set it to :py:const`True` to disable all coloring.

Type:

bool

static _color(color_code, obj)[source]

Color the given object, unless coloring is globally disabled.

Parameters:
  • color_code (int) -- a valid ANSI escape sequence color code.

  • obj (mixed) -- the object to color.

Returns:

the string representation of the object encapsulated in the red ANSI escape sequence.

Return type:

str