Skip to content

Custom Styling of Text with ANSI Escape Codes#

style_text(text, *styles) #

Style text with various options for text and background colors, styling and effects.

Parameters:

Name Type Description Default
text str

The text to be styled.

required
*styles Color | BrightColor | ColorVGA | ColorRGB | ColorHSL | ColorHex | BgColor | BgBrightColor | BgColorVGA | BgColorRGB | BgColorHSL | BgColorHex | Effect | str | None

The text and/or background colors, styling and/or effects to be applied to the text.

()

Returns:

Type Description
str

A new string with the text wrapped in the relevant ANSI escape codes, e.g. style_text("APPROVED", Color.GREEN) yields \033[32mAPPROVED\033[0m.

Example
Python
1
2
3
4
from colorist import style_text, Color, Effect

text = style_text("WARNING", Color.YELLOW, Effect.BOLD, Effect.BLINK)
print(text)

How it appears in the terminal:

% WARNING