Module tenlib.transform.color

Constants and functions to colorize text in the terminal.

Functions

def build_color(spec: str) ‑> Callable[[str], str]

Converts a format specifier into a function that wraps text with ANSI code for colors. Format is at most 3 letters as follow: (foreground color) (background color) (style)

Foreground and background can be any of blue, red, etc. Style can be either empty or a *, indicating we want a bright color. Each of the three letter can be omitted.

Example

# Returns red foreground, blue background, text in bright ANSI
# escape sequence
Colorized.build_color('rB*')('text in red with a blue background')
# Neutral foreground, black background
Colorized.build_color('-X')('text with black background')
# Just yellow
Colorized.build_color('y')('this gets written in yellow')
def bright(string: str) ‑> str
def red(string: str) ‑> str
def blue(string: str) ‑> str
def green(string: str) ‑> str
def magenta(string: str) ‑> str
def yellow(string: str) ‑> str
def white(string: str) ‑> str
def black(string: str) ‑> str
def back_red(string: str) ‑> str
def back_blue(string: str) ‑> str
def back_green(string: str) ‑> str
def back_magenta(string: str) ‑> str
def back_yellow(string: str) ‑> str
def back_white(string: str) ‑> str
def back_black(string: str) ‑> str