aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpux <pux@pux.dom>2020-03-31 12:22:42 +0200
committerpux <pux@pux.dom>2020-03-31 12:22:42 +0200
commitcd630891e73a3edae7926612ecd4192b655936ce (patch)
tree7196a129b569dbe28185e3b5ce06ff6ed6b4d4b2
downloadpyfarbpracht-cd630891e73a3edae7926612ecd4192b655936ce.tar.gz
pyfarbpracht-cd630891e73a3edae7926612ecd4192b655936ce.tar.bz2
pyfarbpracht-cd630891e73a3edae7926612ecd4192b655936ce.zip
moved color print stuff from other projects to here
-rw-r--r--.gitignore2
-rwxr-xr-x__init__.py4
-rwxr-xr-xpyfarbpracht.py39
-rwxr-xr-xtest.py15
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
diff --git a/test.py b/test.py
new file mode 100755
index 0000000..3693134
--- /dev/null
+++ b/test.py
@@ -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()
in each repos: see "about"-tab (if existing) for more details / README.
mailto contact at omeckman dot net
all timestamps in UTC (German winter time: UTC+01:00, summer time: UTC+02:00)
dark theme is a modded version of: https://gist.github.com/Yoplitein/f4b671a2ec70c9e743fa