tab completion in internal shell causes escape mode mess
- Dominant language
- Python
- Stars
- 3.2k
- Forks
- 245
- Avg merge
- 13m
- Merged PRs (30d)
- 5
Description
admittedly, in [sabotage linux](https://github.com/sabotage-linux/sabotage) we have a quite unusual python setup:
- [netbsd-curses](https://github.com/sabotage-linux/netbsd-curses) is used instead of ncurses
- libedit is used instead of readline
nonetheless, i'm reporting the issue i experienced with pudb 2018-1 here for the record.
when the internal shell is selected, and one switched there using '!', as soon as TAB is pressed for the first time for completion (there needs to be something written, for example "a", which would then be completed to e.g. "abs" or "assert"), escapes are broken and every subsequent keypress is displayed as eg `^CC` or similar, but not recognized as such. makes it impossible to exit the shell via CTRL-X. or use backspace, etc. only way out is to kill pudb.
fortunately, i noticed that if i used e.g. the "classic" shell once, then switched to "internal" using preferences, everything behaves as exactly as it should.
this lead me to produce the following patch, which fixes the issue for me.
apparently the readline completer needs to be "initialized" with the code in the patch at least once.
```diff
--- pudb-2018.1/pudb/debugger.py
+++ pudb-2018.1.org/pudb/debugger.py
@@ -1831,7 +1831,13 @@
def run_cmdline(w, size, key):
if CONFIG["shell"] == "internal":
- return toggle_cmdline_focus(w, size, key)
+ curframe = self.debugger.curframe
+ self.screen.stop()
+ import pudb.shell as shell
+ shell.setup_readline(curframe.f_globals, curframe.f_locals)
+ ret = toggle_cmdline_focus(w, size, key)
+ self.screen.start()
+ return ret
else:
return run_external_cmdline(w, size, key)
--- pudb-2018.1/pudb/shell.py
+++ pudb-2018.1.org/pudb/shell.py
@@ -72,14 +72,7 @@
custom_shell_dict = {}
-
-def run_classic_shell(globals, locals, first_time=[True]):
- if first_time:
- banner = "Hit Ctrl-D to return to PuDB."
- first_time.pop()
- else:
- banner = ""
-
+def setup_readline(globals, locals):
ns = SetPropagatingDict([locals, globals], locals)
from pudb.settings import get_save_config_path
@@ -97,6 +90,18 @@
readline.read_history_file(hist_file)
except IOError:
pass
+
+ return hist_file
+
+
+def run_classic_shell(globals, locals, first_time=[True]):
+ if first_time:
+ banner = "Hit Ctrl-D to return to PuDB."
+ first_time.pop()
+ else:
+ banner = ""
+
+ hist_file = setup_readline(globals, locals)
from code import InteractiveConsole
cons = InteractiveConsole(ns)
```
(the self.screen.stop/start is probably not necessary, it's a leftover from my first attempts at fixing)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in pudb/debugger.py at the internal-shell run_cmdline path, then read pudb/shell.py, especially run_classic_shell and the proposed setup_readline separation. Reproduce the issue by selecting the internal shell, entering text, and pressing Tab for completion. Done means completion no longer leaves subsequent keys displayed as escape sequences and controls such as Ctrl-X and backspace work normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100