pint.utils.colorize

pint.utils.colorize(text, fg_color=None, bg_color=None, attribute=None)[source]

Colorizes a string (including unicode strings) for printing on the terminal

For an example of usage, as well as a demonstration as to what the attributes and colors look like, check out print_color_examples()

Parameters:
  • text (string) – The text to colorize. Can include unicode.

  • fg_color (_type_, optional) – Foreground color name. The color names (fg or bg) are one of: ‘black’, ‘red’, ‘green’, ‘yellow’, ‘blue’, ‘magenta’, ‘cyan’, or ‘white’.

  • bg_color (_type_, optional) – Background color name, by default None. Same choices as for fg_color.

  • attribute (_type_, optional) – Text attribute, by default None. The text attributes are one of: ‘normal’, ‘bold’, ‘subdued’, ‘italic’, ‘underscore’, ‘blink’, ‘reverse’, or ‘concealed’.

Returns:

The colorized string using the defined text attribute.

Return type:

string