-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd04d7e
commit e0400e6
Showing
3 changed files
with
35 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .main import shift_lst, dictnamedtuple, easy_argparse | ||
from .pickles import dump_pickle, load_pickle | ||
from .unzip import unzip | ||
from .str_utils import color_str |
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,33 @@ | ||
from typing import Union | ||
|
||
|
||
def color_str(text, color, mode: Union[str, list] = 'bold'): | ||
""" | ||
colorful texts! | ||
:param text: input text | ||
:param color: text color | ||
:param mode: defines text's modes. Valid modes: [ underline, bold ]. Pass a list of modes in case more one mode is needed! | ||
:return: colored text | ||
""" | ||
if isinstance(mode, str): | ||
mode = [mode] | ||
colors = {'black': '\033[30m', # basic colors | ||
'red': '\033[31m', | ||
'green': '\033[32m', | ||
'yellow': '\033[33m', | ||
'blue': '\033[34m', | ||
'magenta': '\033[35m', | ||
'cyan': '\033[36m', | ||
'white': '\033[37m', | ||
'bright_black': '\033[90m', # bright colors | ||
'bright_red': '\033[91m', | ||
'bright_green': '\033[92m', | ||
'bright_yellow': '\033[93m', | ||
'bright_blue': '\033[94m', | ||
'bright_magenta': '\033[95m', | ||
'bright_cyan': '\033[96m', | ||
'bright_white': '\033[97m', | ||
'end': '\033[0m', # misc | ||
'bold': '\033[1m', | ||
'underline': '\033[4m'} | ||
return colors[color] + "".join(colors[m] for m in mode) + text + colors['end'] |
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