]> git.phdru.name Git - dotfiles.git/blobdiff - lib/python/init.py
lib/python/init.py: Call parse_and_bind for libedit and readline
[dotfiles.git] / lib / python / init.py
index 1697a08d38f364db2e2910a639cfc0ad68765697..d8b7c79b89ab8bead28dc330db52457019576765 100644 (file)
@@ -36,6 +36,11 @@ def init():
                 or os.path.expanduser('~/.inputrc')
             readline.read_init_file(initfile)
 
+            #if 'libedit' in readline.__doc__:
+            #    readline.parse_and_bind("bind ^I rl_complete")
+            #else:
+            #    readline.parse_and_bind("tab: complete")
+
             histfile = os.path.expanduser('~/.python_history')
             try:
                 readline.read_history_file(histfile)
@@ -107,6 +112,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:
@@ -152,16 +173,17 @@ def init():
     except ImportError:
         class Pager(BasePager):
             def __init__(self):
-                self.pipe = Popen(pager, shell=True, stdin=PIPE)
+                self.stdout = os.popen(pager, 'w')
+    else:
+        class Pager(BasePager):
+            def __init__(self):
+                self.pipe = Popen(pager, shell=True, stdin=PIPE,
+                                  universal_newlines=True)
                 self.stdout = self.pipe.stdin
 
             def close(self):
                 BasePager.close(self)
                 self.pipe.wait()
-    else:
-        class Pager(BasePager):
-            def __init__(self):
-                self.stdout = os.popen(pager, 'w')
 
     def displayhook(value):
         if value is not None:
@@ -262,10 +284,6 @@ def init():
 
     builtins.x = _Exit()
 
-    # In Python 2.5+ exit and quit are objects
-    if isinstance(builtins.exit, str):
-        builtins.exit = builtins.quit = x  # noqa: x is defined as _Exit
-
     # print conten of a file
 
     class _Cat: