From: Oleg Broytman Date: Wed, 5 Jul 2017 09:31:03 +0000 (+0300) Subject: Fix(lib/python/init.py): Fix stdout for readline X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=702b527246987a7efc3d7e939d02c8b8111eccb1;p=dotfiles.git Fix(lib/python/init.py): Fix stdout for readline Restore stdout during raw_input(). Necessary because readline works only with bare stdout. This fixes code.interact(), django-admin shell and all that. --- diff --git a/lib/python/init.py b/lib/python/init.py index 19f0234..a38cea3 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -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: