From 1a394ae37f06bfb7e0b19f413132530c7c092ba5 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Wed, 24 Apr 2019 22:18:18 +0100 Subject: [PATCH] fix issue with libedit messing up terminal state when switching to the internal shell and using tab completion, libedit messes up the terminal state, unless it uses the readline initialization routine that the "classic" shell code uses as well. additionally to that, it requires that the console screen is stopped before doing that for the first time. fixes #336 --- pudb/debugger.py | 14 +++++++++++++- pudb/shell.py | 28 +++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/pudb/debugger.py b/pudb/debugger.py index 59ac4903..122e7513 100644 --- a/pudb/debugger.py +++ b/pudb/debugger.py @@ -1853,9 +1853,21 @@ def run_external_cmdline(w, size, key): self.update_var_view() + def run_internal_shell(w, size, key, first_time=[True]): + frame = self.debugger.curframe + if first_time: self.screen.stop() + import pudb.shell as sh + histfile, ns = sh.readline_init(frame.f_globals, frame.f_locals) + ret = toggle_cmdline_focus(w, size, key) + sh.readline_fini(histfile) + if first_time: + self.screen.start() + first_time.pop() + return ret + def run_cmdline(w, size, key): if CONFIG["shell"] == "internal": - return toggle_cmdline_focus(w, size, key) + return run_internal_shell(w, size, key) else: return run_external_cmdline(w, size, key) diff --git a/pudb/shell.py b/pudb/shell.py index 4d5763ce..acb0bcf8 100644 --- a/pudb/shell.py +++ b/pudb/shell.py @@ -72,14 +72,7 @@ def __delitem__(self, key): 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 readline_init(globals, locals): ns = SetPropagatingDict([locals, globals], locals) from pudb.settings import get_save_config_path @@ -98,14 +91,27 @@ def run_classic_shell(globals, locals, first_time=[True]): except IOError: pass + return hist_file, ns + +def readline_fini(hist_file): + if HAVE_READLINE: + readline.write_history_file(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, ns = readline_init(globals, locals) + from code import InteractiveConsole cons = InteractiveConsole(ns) cons.interact(banner) - if HAVE_READLINE: - readline.write_history_file(hist_file) - + readline_fini(hist_file) def run_bpython_shell(globals, locals): ns = SetPropagatingDict([locals, globals], locals)