cmdkit.ansi
#
Utility module provides simple methods to colorize text.
Used by the include cmdkit.logging
module to provide
rich highlighting of message attributes.
Reference#
- NO_COLOR: bool#
False
if environment variable is not present.
- FORCE_COLOR: bool#
False
if environment variable is not present.
- enum Ansi(value)[source]#
Classic ANSI escape sequences for colors.
Valid values are as follows:
- NULL = <Ansi.NULL: ''>#
- RESET = <Ansi.RESET: '\x1b[0m'>#
- BOLD = <Ansi.BOLD: '\x1b[1m'>#
- FAINT = <Ansi.FAINT: '\x1b[2m'>#
- ITALIC = <Ansi.ITALIC: '\x1b[3m'>#
- UNDERLINE = <Ansi.UNDERLINE: '\x1b[4m'>#
- BLACK = <Ansi.BLACK: '\x1b[30m'>#
- RED = <Ansi.RED: '\x1b[31m'>#
- GREEN = <Ansi.GREEN: '\x1b[32m'>#
- YELLOW = <Ansi.YELLOW: '\x1b[33m'>#
- BLUE = <Ansi.BLUE: '\x1b[34m'>#
- MAGENTA = <Ansi.MAGENTA: '\x1b[35m'>#
- CYAN = <Ansi.CYAN: '\x1b[36m'>#
- WHITE = <Ansi.WHITE: '\x1b[37m'>#
- format_ansi(seq: Ansi, text: str) str [source]#
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.
- bold(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- faint(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- italic(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- underline(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- black(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- red(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- green(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- yellow(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- blue(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- magenta(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- cyan(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- white(text: str) str #
Apply escape sequence with reset afterward, if necessary. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.Wrapper to
format_ansi()
function.
- colorize_usage(text: str) str [source]#
Apply rich
Ansi
formatting to usage and help text.This function operates like a syntax highlighter for usage and help text. If stdout is not a TTY or
NO_COLOR
is set, there is no effect on text. IfFORCE_COLOR
is set, formatting will be applied regardless.