diff options
author | pux <pux@pux.dom> | 2020-03-31 12:22:42 +0200 |
---|---|---|
committer | pux <pux@pux.dom> | 2020-03-31 12:22:42 +0200 |
commit | cd630891e73a3edae7926612ecd4192b655936ce (patch) | |
tree | 7196a129b569dbe28185e3b5ce06ff6ed6b4d4b2 | |
download | pyfarbpracht-cd630891e73a3edae7926612ecd4192b655936ce.tar.gz pyfarbpracht-cd630891e73a3edae7926612ecd4192b655936ce.tar.bz2 pyfarbpracht-cd630891e73a3edae7926612ecd4192b655936ce.zip |
moved color print stuff from other projects to here
-rw-r--r-- | .gitignore | 2 | ||||
-rwxr-xr-x | __init__.py | 4 | ||||
-rwxr-xr-x | pyfarbpracht.py | 39 | ||||
-rwxr-xr-x | test.py | 15 |
4 files changed, 60 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..58af8a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +*.py[cod] diff --git a/__init__.py b/__init__.py new file mode 100755 index 0000000..f5afe4c --- /dev/null +++ b/__init__.py @@ -0,0 +1,4 @@ +__pkg__name = 'pyfarbpracht' +__version_ = 1 + +import pyfarbpracht diff --git a/pyfarbpracht.py b/pyfarbpracht.py new file mode 100755 index 0000000..bb5e041 --- /dev/null +++ b/pyfarbpracht.py @@ -0,0 +1,39 @@ +from os import linesep + +# print with color support +def printc(color, msg, no_newline=False, enable_color=False): + ret = str() + if enable_color: + ret += colored(color, msg) + else: + ret += msg + if no_newline: + end = '' + else: + end = linesep + print(ret, end=end) + return ret + +# print with color support +def colored(color, msg): + 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' + ret += msg + # reset color + ret += '\033[0m' + return ret @@ -0,0 +1,15 @@ +#!/bin/env python + +import pyfarbpracht + +def test(): + ret = pyfarbpracht.printc('green', 'green test with newline', enable_color=True) + print(ret) + ret = pyfarbpracht.printc('cyan', 'cyan but enable_color=False', enable_color=False) + print(ret) + ret = pyfarbpracht.printc('magenta', 'magenta no newline', enable_color=True, no_newline=True) + print(ret) + print(ret) + +if __name__ == '__main__': + test() |