Skip to content

Commit 87ce98b

Browse files
committed
allow colorize to use color codes
Signed-off-by: Zen <[email protected]>
1 parent cedd156 commit 87ce98b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/zenlib/util/colorize.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.1"
1+
__version__ = "0.2.0"
22

33
from enum import Enum
44

@@ -29,5 +29,13 @@ def __str__(self):
2929

3030

3131
def colorize(text: str, color="white", bright=False, bold=False) -> str:
32-
color_code = Colors[color.upper()].value
32+
try:
33+
color_code = Colors[color.upper()].value
34+
except (KeyError, AttributeError):
35+
try:
36+
color_code = int(color)
37+
except ValueError:
38+
raise ValueError(f"Invalid color: {color}")
39+
color_code = int(color)
40+
3341
return f"{ANSICode(color_code, bright, bold)}{text}{ANSICode(0)}"

0 commit comments

Comments
 (0)