summaryrefslogtreecommitdiffstats
path: root/colorclass/__main__.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-16 09:10:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-16 09:10:14 +0000
commit896739353a613f23c007d9acaa2809010a522a37 (patch)
treecadd194400c11d0a5caaeda7d9d771602eb1ba40 /colorclass/__main__.py
parentInitial commit. (diff)
downloadcolorclass-896739353a613f23c007d9acaa2809010a522a37.tar.xz
colorclass-896739353a613f23c007d9acaa2809010a522a37.zip
Adding upstream version 2.2.0.upstream/2.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'colorclass/__main__.py')
-rw-r--r--colorclass/__main__.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/colorclass/__main__.py b/colorclass/__main__.py
new file mode 100644
index 0000000..d8f3f00
--- /dev/null
+++ b/colorclass/__main__.py
@@ -0,0 +1,33 @@
+"""Called by "python -m". Allows package to be used as a script.
+
+Example usage:
+echo "{red}Red{/red}" |python -m colorclass
+"""
+
+from __future__ import print_function
+
+import fileinput
+import os
+
+from colorclass.color import Color
+from colorclass.toggles import disable_all_colors
+from colorclass.toggles import enable_all_colors
+from colorclass.toggles import set_dark_background
+from colorclass.toggles import set_light_background
+from colorclass.windows import Windows
+
+TRUTHY = ('true', '1', 'yes', 'on')
+
+
+if __name__ == '__main__':
+ if os.environ.get('COLOR_ENABLE', '').lower() in TRUTHY:
+ enable_all_colors()
+ elif os.environ.get('COLOR_DISABLE', '').lower() in TRUTHY:
+ disable_all_colors()
+ if os.environ.get('COLOR_LIGHT', '').lower() in TRUTHY:
+ set_light_background()
+ elif os.environ.get('COLOR_DARK', '').lower() in TRUTHY:
+ set_dark_background()
+ Windows.enable()
+ for LINE in fileinput.input():
+ print(Color(LINE))