summaryrefslogtreecommitdiffstats
path: root/pyload/lib/colorama/initialise.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-09-08 01:16:38 +0200
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-09-14 11:03:34 +0200
commitbe1df32bd3faa571343913da7f88d6b40378b195 (patch)
treefb2d9ff8ce2eb57d0ed42657dcc8be53f972c03d /pyload/lib/colorama/initialise.py
parentRestructure pyload file tree (1) (diff)
downloadpyload-be1df32bd3faa571343913da7f88d6b40378b195.tar.xz
New printer (windows compatible)
Diffstat (limited to 'pyload/lib/colorama/initialise.py')
-rw-r--r--pyload/lib/colorama/initialise.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/pyload/lib/colorama/initialise.py b/pyload/lib/colorama/initialise.py
new file mode 100644
index 000000000..7e27f84f8
--- /dev/null
+++ b/pyload/lib/colorama/initialise.py
@@ -0,0 +1,66 @@
+# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
+import atexit
+import sys
+
+from .ansitowin32 import AnsiToWin32
+
+
+orig_stdout = sys.stdout
+orig_stderr = sys.stderr
+
+wrapped_stdout = sys.stdout
+wrapped_stderr = sys.stderr
+
+atexit_done = False
+
+
+def reset_all():
+ AnsiToWin32(orig_stdout).reset_all()
+
+
+def init(autoreset=False, convert=None, strip=None, wrap=True):
+
+ if not wrap and any([autoreset, convert, strip]):
+ raise ValueError('wrap=False conflicts with any other arg=True')
+
+ global wrapped_stdout, wrapped_stderr
+ if sys.stdout is None:
+ wrapped_stdout = None
+ else:
+ sys.stdout = wrapped_stdout = \
+ wrap_stream(orig_stdout, convert, strip, autoreset, wrap)
+ if sys.stderr is None:
+ wrapped_stderr = None
+ else:
+ sys.stderr = wrapped_stderr = \
+ wrap_stream(orig_stderr, convert, strip, autoreset, wrap)
+
+ global atexit_done
+ if not atexit_done:
+ atexit.register(reset_all)
+ atexit_done = True
+
+
+def deinit():
+ if orig_stdout is not None:
+ sys.stdout = orig_stdout
+ if orig_stderr is not None:
+ sys.stderr = orig_stderr
+
+
+def reinit():
+ if wrapped_stdout is not None:
+ sys.stdout = wrapped_stdout
+ if wrapped_stderr is not None:
+ sys.stderr = wrapped_stderr
+
+
+def wrap_stream(stream, convert, strip, autoreset, wrap):
+ if wrap:
+ wrapper = AnsiToWin32(stream,
+ convert=convert, strip=strip, autoreset=autoreset)
+ if wrapper.should_wrap():
+ stream = wrapper.stream
+ return stream
+
+