Fore.aliceblue, Back.blue, Style.bold
('\x1b[38;2;240;248;255m', '\x1b[48;2;0;0;255m', '\x1b[01m')
Basic usage:
Fore
and Back
also suport rgb and hex format:
Fore['123, 242, 5'], Fore['(123, 242, 5)'], Fore['#ffffff']
Back['123, 242, 5'], Back['(123, 242, 5)'], Back['#ffffff']
_AnsiColor (name='fore')
name: style, fore, back
You could use Fore
, Back
and Style
to get the text foreground, background and style ansi escape code. If the input is not accepted, they would return empty string ''
Some ansi escape code example:
Only Back
and Style
support uppercase.
Basic usage:
Other available colors are in Fore.available
:
def _get_background(color):
background = (
Back['75, 70, 75']
if sum(Color[color].rgb) / 3 > 165 else
Back['240, 250, 250']
)
return background
for i, c in enumerate(Fore.available):
background = _get_background(c)
print(background, end='')
end = '\n' if (i+1) % 4 == 0 else '\t'
print(f'{Fore[c]}{c:21s}{Fore.reset}', end=end)
print(Back.reset_all)
Fore
also support rgb and hex format:
('\x1b[38;2;1;2;3m', '\x1b[38;2;255;255;255m', '\x1b[38;2;111;222;55m')
Basic usage:
Other available colors are in Back.available
:
def _get_foreground(color):
foreground = (
Fore['5, 7, 7']
if sum(Color[color].rgb) / 3 > 160 else
Fore['255, 250, 250']
)
return foreground
for i, c in enumerate(Back.available):
foreground = _get_foreground(c)
print(foreground, end='')
end = '\n' if (i+1) % 4 == 0 else '\t'
print(f'{Back[c]}{c:21s}{Back.reset}', end=end)
print(Fore.reset)
Back
also support rgb and hex format:
('\x1b[48;2;1;2;3m', '\x1b[48;2;255;255;255m', '\x1b[48;2;111;222;55m')
Fore
and Back
also support 8-bits color:
Basic usage:
Only list the commonly used styles
“reset_all” and “end” would reset all the ansi escape code function
AnsiColor (fore:str=None, back:str=None, style:str=None)
Integrate with Fore
, Back
, Style
.
Type | Default | Details | |
---|---|---|---|
fore | str | None | Foreground color. Could be hex, rgb string or tuple, Fore , 8-bits color |
back | str | None | Background color, Could be hex, rgb string or tuple, Back , 8-bits color |
style | str | None | Text style. Seee Style.available . |
Basic usage: