diff options
Diffstat (limited to 'pyfarbpracht/pyfarbpracht.py')
-rwxr-xr-x | pyfarbpracht/pyfarbpracht.py | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/pyfarbpracht/pyfarbpracht.py b/pyfarbpracht/pyfarbpracht.py index 2422699..d41842b 100755 --- a/pyfarbpracht/pyfarbpracht.py +++ b/pyfarbpracht/pyfarbpracht.py @@ -19,22 +19,29 @@ def printc(color, msg, no_newline=False, enable_color=False): def colored(color, msg): """returns msg in ANSI color""" ret = str() - c = 'default' - if color == 'red': - c = '31' - elif color == 'green': - c = '32' - elif color == 'yellow': - c = '33' - elif color == 'blue': - c = '34' - elif color == 'magenta': - c = '35' - elif color == 'cyan': - c = '36' - if c is not 'default': - # set color - ret += '\033[0;' + c + 'm' + if color.startswith("#"): + ret += '\033[38;2;' + ret += str(int(color[1:3], 16)) + ';' \ + + str(int(color[3:5], 16)) + ';' \ + + str(int(color[5:7], 16)) + ret += 'm' + else: + c = 'default' + if color == 'red': + c = '31' + elif color == 'green': + c = '32' + elif color == 'yellow': + c = '33' + elif color == 'blue': + c = '34' + elif color == 'magenta': + c = '35' + elif color == 'cyan': + c = '36' + if c is not 'default': + # set color + ret += '\033[0;' + c + 'm' ret += msg # reset color ret += '\033[0m' |