Show More
@@ -20,6 +20,9 b' class TerminalPdb(Pdb):' | |||||
20 | def get_prompt_tokens(cli): |
|
20 | def get_prompt_tokens(cli): | |
21 | return [(Token.Prompt, self.prompt)] |
|
21 | return [(Token.Prompt, self.prompt)] | |
22 |
|
22 | |||
|
23 | def patch_stdout(**kwargs): | |||
|
24 | return self.pt_cli.patch_stdout_context(**kwargs) | |||
|
25 | ||||
23 | if self._ptcomp is None: |
|
26 | if self._ptcomp is None: | |
24 | compl = IPCompleter(shell=self.shell, |
|
27 | compl = IPCompleter(shell=self.shell, | |
25 | namespace={}, |
|
28 | namespace={}, | |
@@ -27,7 +30,7 b' class TerminalPdb(Pdb):' | |||||
27 | use_readline=False, |
|
30 | use_readline=False, | |
28 | parent=self.shell, |
|
31 | parent=self.shell, | |
29 | ) |
|
32 | ) | |
30 | self._ptcomp = IPythonPTCompleter(compl) |
|
33 | self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout) | |
31 |
|
34 | |||
32 | self._pt_app = create_prompt_application( |
|
35 | self._pt_app = create_prompt_application( | |
33 | editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), |
|
36 | editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), |
@@ -237,11 +237,15 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
237 |
|
237 | |||
238 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) |
|
238 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) | |
239 |
|
239 | |||
|
240 | def patch_stdout(**kwargs): | |||
|
241 | return self.pt_cli.patch_stdout_context(**kwargs) | |||
|
242 | ||||
240 | self._pt_app = create_prompt_application( |
|
243 | self._pt_app = create_prompt_application( | |
241 | editing_mode=editing_mode, |
|
244 | editing_mode=editing_mode, | |
242 | key_bindings_registry=kbmanager.registry, |
|
245 | key_bindings_registry=kbmanager.registry, | |
243 | history=history, |
|
246 | history=history, | |
244 |
completer=IPythonPTCompleter(shell=self |
|
247 | completer=IPythonPTCompleter(shell=self, | |
|
248 | patch_stdout=patch_stdout), | |||
245 | enable_history_search=True, |
|
249 | enable_history_search=True, | |
246 | style=style, |
|
250 | style=style, | |
247 | mouse_support=self.mouse_support, |
|
251 | mouse_support=self.mouse_support, |
@@ -22,11 +22,14 b' import pygments.lexers as pygments_lexers' | |||||
22 |
|
22 | |||
23 | class IPythonPTCompleter(Completer): |
|
23 | class IPythonPTCompleter(Completer): | |
24 | """Adaptor to provide IPython completions to prompt_toolkit""" |
|
24 | """Adaptor to provide IPython completions to prompt_toolkit""" | |
25 | def __init__(self, ipy_completer=None, shell=None): |
|
25 | def __init__(self, ipy_completer=None, shell=None, patch_stdout=None): | |
26 | if shell is None and ipy_completer is None: |
|
26 | if shell is None and ipy_completer is None: | |
27 | raise TypeError("Please pass shell=an InteractiveShell instance.") |
|
27 | raise TypeError("Please pass shell=an InteractiveShell instance.") | |
28 | self._ipy_completer = ipy_completer |
|
28 | self._ipy_completer = ipy_completer | |
29 | self.shell = shell |
|
29 | self.shell = shell | |
|
30 | if patch_stdout is None: | |||
|
31 | raise TypeError("Please pass patch_stdout") | |||
|
32 | self.patch_stdout = patch_stdout | |||
30 |
|
33 | |||
31 | @property |
|
34 | @property | |
32 | def ipy_completer(self): |
|
35 | def ipy_completer(self): | |
@@ -42,7 +45,7 b' class IPythonPTCompleter(Completer):' | |||||
42 | # Some bits of our completion system may print stuff (e.g. if a module |
|
45 | # Some bits of our completion system may print stuff (e.g. if a module | |
43 | # is imported). This context manager ensures that doesn't interfere with |
|
46 | # is imported). This context manager ensures that doesn't interfere with | |
44 | # the prompt. |
|
47 | # the prompt. | |
45 |
with self. |
|
48 | with self.patch_stdout(): | |
46 | used, matches = self.ipy_completer.complete( |
|
49 | used, matches = self.ipy_completer.complete( | |
47 | line_buffer=document.current_line, |
|
50 | line_buffer=document.current_line, | |
48 | cursor_pos=document.cursor_position_col |
|
51 | cursor_pos=document.cursor_position_col |
General Comments 0
You need to be logged in to leave comments.
Login now