diff --git a/IPython/terminal/debugger.py b/IPython/terminal/debugger.py index 810299e..bad6c3e 100644 --- a/IPython/terminal/debugger.py +++ b/IPython/terminal/debugger.py @@ -20,13 +20,16 @@ class TerminalPdb(Pdb): def get_prompt_tokens(cli): return [(Token.Prompt, self.prompt)] + def patch_stdout(**kwargs): + return self.pt_cli.patch_stdout_context(**kwargs) + if self._ptcomp is None: compl = IPCompleter(shell=self.shell, namespace={}, global_namespace={}, parent=self.shell, ) - self._ptcomp = IPythonPTCompleter(compl) + self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout) self._pt_app = create_prompt_application( editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index a9d2162..f1b97ca 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -233,11 +233,15 @@ class TerminalInteractiveShell(InteractiveShell): editing_mode = getattr(EditingMode, self.editing_mode.upper()) + def patch_stdout(**kwargs): + return self.pt_cli.patch_stdout_context(**kwargs) + self._pt_app = create_prompt_application( editing_mode=editing_mode, key_bindings_registry=kbmanager.registry, history=history, - completer=IPythonPTCompleter(shell=self), + completer=IPythonPTCompleter(shell=self, + patch_stdout=patch_stdout), enable_history_search=True, style=style, mouse_support=self.mouse_support, diff --git a/IPython/terminal/ptutils.py b/IPython/terminal/ptutils.py index 56e2ebd..593501a 100644 --- a/IPython/terminal/ptutils.py +++ b/IPython/terminal/ptutils.py @@ -20,11 +20,14 @@ import pygments.lexers as pygments_lexers class IPythonPTCompleter(Completer): """Adaptor to provide IPython completions to prompt_toolkit""" - def __init__(self, ipy_completer=None, shell=None): + def __init__(self, ipy_completer=None, shell=None, patch_stdout=None): if shell is None and ipy_completer is None: raise TypeError("Please pass shell=an InteractiveShell instance.") self._ipy_completer = ipy_completer self.shell = shell + if patch_stdout is None: + raise TypeError("Please pass patch_stdout") + self.patch_stdout = patch_stdout @property def ipy_completer(self): @@ -40,7 +43,7 @@ class IPythonPTCompleter(Completer): # Some bits of our completion system may print stuff (e.g. if a module # is imported). This context manager ensures that doesn't interfere with # the prompt. - with self.shell.pt_cli.patch_stdout_context(): + with self.patch_stdout(): used, matches = self.ipy_completer.complete( line_buffer=document.current_line, cursor_pos=document.cursor_position_col