]> git.phdru.name Git - dotfiles.git/commitdiff
lib/python/init.py: Use `pyreadline`/`pyreadline3`
authorOleg Broytman <phd@phdru.name>
Sun, 11 Jan 2026 04:14:06 +0000 (07:14 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 11 Jan 2026 11:10:29 +0000 (14:10 +0300)
lib/python/init.py

index ce7f1f48d536df57281acc7806f0ff186f050396..7249b4a252721afc1f2a807f88ed47d0e7dcc457 100644 (file)
@@ -33,6 +33,26 @@ def init():
                 category=UserWarning)
             readline.read_init_file(initfile)
 
+        try:
+            import pyreadline3.rlmain
+            import pyreadline3.unicode_helper  # noqa: F401 imported but unused
+        except ImportError:
+            try:
+                import pyreadline.rlmain
+                import pyreadline.unicode_helper  # noqa: F401 unused
+            except ImportError:
+                pass
+
+        # Copied from pyreadline/configuration/startup.py
+        completer_obj = rlcompleter.Completer()
+        # def nop(val, word):
+        #     return word
+        # completer_obj._callable_postfix = nop
+        readline.set_completer(completer_obj.complete)
+
+        # activate tab completion
+        readline.parse_and_bind("tab: complete")
+
         # if 'libedit' in readline.__doc__:
         #     readline.parse_and_bind("bind ^I rl_complete")
         # else:
@@ -74,11 +94,13 @@ def init():
                 import atexit
                 atexit._exithandlers = []
             builtins.unset_history = unset_history2
+
         elif hasattr(atexit, '_clear') and callable(atexit._clear):
             def unset_history3():
                 import atexit
                 atexit._clear()
             builtins.unset_history = unset_history3
+
         else:
             sys.stderr.write('Error: cannot clear exit handlers\n')