-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/better log: Add colorize function and TermColor enum for text co…
…loring (#5410) Co-authored-by: Engel Nyst <[email protected]>
- Loading branch information
1 parent
6972f48
commit 424cdf1
Showing
4 changed files
with
51 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from enum import Enum | ||
|
||
from termcolor import colored | ||
|
||
|
||
class TermColor(Enum): | ||
"""Terminal color codes.""" | ||
|
||
WARNING = 'yellow' | ||
SUCCESS = 'green' | ||
ERROR = 'red' | ||
INFO = 'blue' | ||
|
||
|
||
def colorize(text: str, color: TermColor = TermColor.WARNING) -> str: | ||
"""Colorize text with specified color. | ||
Args: | ||
text (str): Text to be colored | ||
color (TermColor, optional): Color to use. Defaults to TermColor.WARNING | ||
Returns: | ||
str: Colored text | ||
""" | ||
return colored(text, color.value) |