forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatting_utils.py
70 lines (65 loc) · 1.65 KB
/
formatting_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from __future__ import annotations
from typing import Iterable, Literal
try:
from termcolor import colored
except ImportError:
# termcolor is an optional dependency - if it cannot be imported then no color is used.
# Alternatively the envvar NO_COLOR can be used to disable color.
# To allow for proper typing and for termcolor to be optional we need to re-define the types used in the lib here.
# This is the direct function definition from termcolor.
Attribute = Literal[
"bold",
"dark",
"underline",
"blink",
"reverse",
"concealed",
]
Highlight = Literal[
"on_black",
"on_grey",
"on_red",
"on_green",
"on_yellow",
"on_blue",
"on_magenta",
"on_cyan",
"on_light_grey",
"on_dark_grey",
"on_light_red",
"on_light_green",
"on_light_yellow",
"on_light_blue",
"on_light_magenta",
"on_light_cyan",
"on_white",
]
Color = Literal[
"black",
"grey",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"light_grey",
"dark_grey",
"light_red",
"light_green",
"light_yellow",
"light_blue",
"light_magenta",
"light_cyan",
"white",
]
def colored(
text: object,
color: Color | None = None,
on_color: Highlight | None = None,
attrs: Iterable[Attribute] | None = None,
*,
no_color: bool | None = None,
force_color: bool | None = None,
) -> str:
return str(text)