]> git.phdru.name Git - dotfiles.git/commitdiff
Fix(lib/python/init.py): Fix stdout for readline
authorOleg Broytman <phd@phdru.name>
Wed, 5 Jul 2017 09:31:03 +0000 (12:31 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 5 Jul 2017 09:31:03 +0000 (12:31 +0300)
Restore stdout during raw_input().
Necessary because readline works only with bare stdout.
This fixes code.interact(), django-admin shell and all that.

lib/python/init.py

index 19f02346be99db0af56f66db21fa9813bb023760..a38cea39332d3904ffd2313d2abfc4e6607688fb 100644 (file)
@@ -107,6 +107,22 @@ def init():
         sys.stdout = ColoredFile(sys.stdout, '\033[1;3%sm' % stdout_color)
         sys.stderr = ColoredFile(sys.stderr, '\033[31m')  # red
 
+        def myinput(prompt=None):
+            save_stdout = sys.stdout
+            sys.stdout = sys.__stdout__
+            result = builtin_input(prompt)
+            sys.stdout = save_stdout
+            return result
+
+        try:
+            builtins.raw_input
+        except AttributeError: # PY3
+            builtin_input = builtins.input
+            builtins.input = myinput
+        else:
+            builtin_input = builtins.raw_input
+            builtins.raw_input = myinput
+
         break
 
     try: