colors#

This module contains a very much simplified implementation of click module to allow for string coloring.

It is not intended to be used as standalone, but as part of the ColorFormatter class. Unless you need to color your strings somewhere else!

This module also provides structures with RGB and string named colors

click#

class pocketwelt.colors.click#

Bases: object

This class was made to simulate click (see: pallets/click) package coloring functionality.

My goal was to keep the package fully built-in, so if you do not have this package installed, there will be no problem with using the style() method.

However, if it is installed, do not worry - this class is only used in logs.ColorFormatter and is imported only when real click is not installed.

classmethod style(text: str, fg: int | RGBColor | str, **style_kwargs) str#

Style a text with ANSI color codes.

Parameters:
  • text (str) – The text to be styled.

  • fg (Union[int, RGBColor, str]) – The foreground color. Can be an integer, RGBColor, or a string representing the color.

  • **style_kwargs – Options from the original click.style method.

Returns:

The styled text with ANSI color codes.

Return type:

str

_ANSI_COLORS#

Dictionary with human-readable color names and their ANSI codes:

from pocketwelt.colors import _ANSI_COLORS

RGBColor#

Enumerator with color names and their corresponding RGB color tuples:

from pocketwelt.colors import RGBColor

# Extract tuple (255, 0 , 0)
red = RGBColor.RED