Show More
@@ -39,8 +39,11 b' from IPython.core.excolors import exception_colors' | |||||
39 | from IPython.testing.skipdoctest import skip_doctest |
|
39 | from IPython.testing.skipdoctest import skip_doctest | |
40 | from IPython.terminal.ptutils import IPythonPTCompleter |
|
40 | from IPython.terminal.ptutils import IPythonPTCompleter | |
41 |
|
41 | |||
42 | from prompt_toolkit import prompt as ptk_prompt |
|
|||
43 | from prompt_toolkit.token import Token |
|
42 | from prompt_toolkit.token import Token | |
|
43 | from prompt_toolkit.shortcuts import create_prompt_application | |||
|
44 | from prompt_toolkit.interface import CommandLineInterface | |||
|
45 | from prompt_toolkit.enums import EditingMode | |||
|
46 | ||||
44 |
|
47 | |||
45 | prompt = 'ipdb> ' |
|
48 | prompt = 'ipdb> ' | |
46 |
|
49 | |||
@@ -204,7 +207,7 b' class Pdb(OldPdb, object):' | |||||
204 | except (TypeError, ValueError): |
|
207 | except (TypeError, ValueError): | |
205 | raise ValueError("Context must be a positive integer") |
|
208 | raise ValueError("Context must be a positive integer") | |
206 |
|
209 | |||
207 | OldPdb.__init__(self,completekey,stdin,stdout) |
|
210 | OldPdb.__init__(self, completekey, stdin, stdout) | |
208 |
|
211 | |||
209 | # IPython changes... |
|
212 | # IPython changes... | |
210 | self.shell = get_ipython() |
|
213 | self.shell = get_ipython() | |
@@ -217,7 +220,6 b' class Pdb(OldPdb, object):' | |||||
217 |
|
220 | |||
218 | # This is icky, but I'm not currently sure how best to test if we're |
|
221 | # This is icky, but I'm not currently sure how best to test if we're | |
219 | # in a terminal shell using prompt_toolkit |
|
222 | # in a terminal shell using prompt_toolkit | |
220 | self.use_prompt_toolkit = hasattr(self.shell, 'pt_cli') |
|
|||
221 |
|
223 | |||
222 | self.aliases = {} |
|
224 | self.aliases = {} | |
223 |
|
225 | |||
@@ -250,6 +252,36 b' class Pdb(OldPdb, object):' | |||||
250 | # Set the prompt - the default prompt is '(Pdb)' |
|
252 | # Set the prompt - the default prompt is '(Pdb)' | |
251 | self.prompt = prompt |
|
253 | self.prompt = prompt | |
252 | self._ptcomp = None |
|
254 | self._ptcomp = None | |
|
255 | self.pt_init() | |||
|
256 | ||||
|
257 | def pt_init(self): | |||
|
258 | self.use_prompt_toolkit = hasattr(self.shell, 'pt_cli') | |||
|
259 | ||||
|
260 | if not self.use_prompt_toolkit: | |||
|
261 | return | |||
|
262 | ||||
|
263 | def get_prompt_tokens(cli): | |||
|
264 | return [(Token.Prompt, self.prompt)] | |||
|
265 | ||||
|
266 | if self._ptcomp is None: | |||
|
267 | compl = IPCompleter(shell=self.shell, | |||
|
268 | namespace={}, | |||
|
269 | global_namespace={}, | |||
|
270 | use_readline=False, | |||
|
271 | parent=self.shell, | |||
|
272 | ) | |||
|
273 | self._ptcomp = IPythonPTCompleter(compl) | |||
|
274 | ||||
|
275 | self._pt_app = create_prompt_application( | |||
|
276 | editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), | |||
|
277 | history=self.shell.debugger_history, | |||
|
278 | completer= self._ptcomp, | |||
|
279 | enable_history_search=True, | |||
|
280 | mouse_support=self.shell.mouse_support, | |||
|
281 | get_prompt_tokens=get_prompt_tokens | |||
|
282 | ) | |||
|
283 | self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop) | |||
|
284 | ||||
253 |
|
285 | |||
254 |
|
286 | |||
255 | def cmdloop(self, intro=None): |
|
287 | def cmdloop(self, intro=None): | |
@@ -265,19 +297,9 b' class Pdb(OldPdb, object):' | |||||
265 | if not self.use_rawinput: |
|
297 | if not self.use_rawinput: | |
266 | raise ValueError('Sorry ipdb does not support raw_input=False') |
|
298 | raise ValueError('Sorry ipdb does not support raw_input=False') | |
267 |
|
299 | |||
268 | def get_prompt_tokens(cli): |
|
|||
269 | return [(Token.Prompt, self.prompt)] |
|
|||
270 |
|
300 | |||
271 | self.preloop() |
|
301 | self.preloop() | |
272 |
|
302 | |||
273 | if self._ptcomp is None: |
|
|||
274 | compl = IPCompleter(shell=self.shell, |
|
|||
275 | namespace=self.curframe_locals, |
|
|||
276 | global_namespace=self.curframe.f_globals, |
|
|||
277 | use_readline=False, |
|
|||
278 | parent=self.shell, |
|
|||
279 | ) |
|
|||
280 | self._ptcomp = IPythonPTCompleter(compl) |
|
|||
281 |
|
303 | |||
282 | try: |
|
304 | try: | |
283 | if intro is not None: |
|
305 | if intro is not None: | |
@@ -292,10 +314,7 b' class Pdb(OldPdb, object):' | |||||
292 | self._ptcomp.ipy_completer.namespace = self.curframe_locals |
|
314 | self._ptcomp.ipy_completer.namespace = self.curframe_locals | |
293 | self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals |
|
315 | self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals | |
294 | try: |
|
316 | try: | |
295 | line = ptk_prompt(get_prompt_tokens=get_prompt_tokens, |
|
317 | line = self.pt_cli.run(reset_current_buffer=True).text | |
296 | history=self.shell.debugger_history, |
|
|||
297 | completer=self._ptcomp |
|
|||
298 | ) |
|
|||
299 | except EOFError: |
|
318 | except EOFError: | |
300 | line = 'EOF' |
|
319 | line = 'EOF' | |
301 | line = self.precmd(line) |
|
320 | line = self.precmd(line) | |
@@ -303,7 +322,7 b' class Pdb(OldPdb, object):' | |||||
303 | stop = self.postcmd(stop, line) |
|
322 | stop = self.postcmd(stop, line) | |
304 | self.postloop() |
|
323 | self.postloop() | |
305 | except Exception: |
|
324 | except Exception: | |
306 |
|
|
325 | raise | |
307 |
|
326 | |||
308 |
|
327 | |||
309 |
|
328 |
General Comments 0
You need to be logged in to leave comments.
Login now