Show More
@@ -0,0 +1,73 b'' | |||||
|
1 | from IPython.core.debugger import Pdb | |||
|
2 | ||||
|
3 | from IPython.core.completer import IPCompleter | |||
|
4 | from .ptutils import IPythonPTCompleter | |||
|
5 | ||||
|
6 | from prompt_toolkit.token import Token | |||
|
7 | from prompt_toolkit.shortcuts import create_prompt_application | |||
|
8 | from prompt_toolkit.interface import CommandLineInterface | |||
|
9 | from prompt_toolkit.enums import EditingMode | |||
|
10 | ||||
|
11 | class TerminalPdb(Pdb): | |||
|
12 | def __init__(self, *args, **kwargs): | |||
|
13 | Pdb.__init__(self, *args, **kwargs) | |||
|
14 | self._ptcomp = None | |||
|
15 | self.pt_init() | |||
|
16 | ||||
|
17 | def pt_init(self): | |||
|
18 | def get_prompt_tokens(cli): | |||
|
19 | return [(Token.Prompt, self.prompt)] | |||
|
20 | ||||
|
21 | if self._ptcomp is None: | |||
|
22 | compl = IPCompleter(shell=self.shell, | |||
|
23 | namespace={}, | |||
|
24 | global_namespace={}, | |||
|
25 | use_readline=False, | |||
|
26 | parent=self.shell, | |||
|
27 | ) | |||
|
28 | self._ptcomp = IPythonPTCompleter(compl) | |||
|
29 | ||||
|
30 | self._pt_app = create_prompt_application( | |||
|
31 | editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), | |||
|
32 | history=self.shell.debugger_history, | |||
|
33 | completer= self._ptcomp, | |||
|
34 | enable_history_search=True, | |||
|
35 | mouse_support=self.shell.mouse_support, | |||
|
36 | get_prompt_tokens=get_prompt_tokens | |||
|
37 | ) | |||
|
38 | self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop) | |||
|
39 | ||||
|
40 | def cmdloop(self, intro=None): | |||
|
41 | """Repeatedly issue a prompt, accept input, parse an initial prefix | |||
|
42 | off the received input, and dispatch to action methods, passing them | |||
|
43 | the remainder of the line as argument. | |||
|
44 | ||||
|
45 | override the same methods from cmd.Cmd to provide prompt toolkit replacement. | |||
|
46 | """ | |||
|
47 | if not self.use_rawinput: | |||
|
48 | raise ValueError('Sorry ipdb does not support use_rawinput=False') | |||
|
49 | ||||
|
50 | self.preloop() | |||
|
51 | ||||
|
52 | try: | |||
|
53 | if intro is not None: | |||
|
54 | self.intro = intro | |||
|
55 | if self.intro: | |||
|
56 | self.stdout.write(str(self.intro)+"\n") | |||
|
57 | stop = None | |||
|
58 | while not stop: | |||
|
59 | if self.cmdqueue: | |||
|
60 | line = self.cmdqueue.pop(0) | |||
|
61 | else: | |||
|
62 | self._ptcomp.ipy_completer.namespace = self.curframe_locals | |||
|
63 | self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals | |||
|
64 | try: | |||
|
65 | line = self.pt_cli.run(reset_current_buffer=True).text | |||
|
66 | except EOFError: | |||
|
67 | line = 'EOF' | |||
|
68 | line = self.precmd(line) | |||
|
69 | stop = self.onecmd(line) | |||
|
70 | stop = self.postcmd(stop, line) | |||
|
71 | self.postloop() | |||
|
72 | except Exception: | |||
|
73 | raise |
@@ -34,15 +34,8 b' import sys' | |||||
34 | from IPython import get_ipython |
|
34 | from IPython import get_ipython | |
35 | from IPython.utils import PyColorize, ulinecache |
|
35 | from IPython.utils import PyColorize, ulinecache | |
36 | from IPython.utils import coloransi, py3compat |
|
36 | from IPython.utils import coloransi, py3compat | |
37 | from IPython.core.completer import IPCompleter |
|
|||
38 | from IPython.core.excolors import exception_colors |
|
37 | from IPython.core.excolors import exception_colors | |
39 | from IPython.testing.skipdoctest import skip_doctest |
|
38 | from IPython.testing.skipdoctest import skip_doctest | |
40 | from IPython.terminal.ptutils import IPythonPTCompleter |
|
|||
41 |
|
||||
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 |
|
39 | |||
47 |
|
40 | |||
48 | prompt = 'ipdb> ' |
|
41 | prompt = 'ipdb> ' | |
@@ -251,80 +244,6 b' class Pdb(OldPdb, object):' | |||||
251 |
|
244 | |||
252 | # Set the prompt - the default prompt is '(Pdb)' |
|
245 | # Set the prompt - the default prompt is '(Pdb)' | |
253 | self.prompt = prompt |
|
246 | self.prompt = prompt | |
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 |
|
||||
285 |
|
||||
286 |
|
||||
287 | def cmdloop(self, intro=None): |
|
|||
288 | """Repeatedly issue a prompt, accept input, parse an initial prefix |
|
|||
289 | off the received input, and dispatch to action methods, passing them |
|
|||
290 | the remainder of the line as argument. |
|
|||
291 |
|
||||
292 | override the same methods from cmd.Cmd to provide prompt toolkit replacement. |
|
|||
293 | """ |
|
|||
294 | if not self.use_prompt_toolkit: |
|
|||
295 | return OldPdb.cmdloop(self, intro) |
|
|||
296 |
|
||||
297 | if not self.use_rawinput: |
|
|||
298 | raise ValueError('Sorry ipdb does not support raw_input=False') |
|
|||
299 |
|
||||
300 |
|
||||
301 | self.preloop() |
|
|||
302 |
|
||||
303 |
|
||||
304 | try: |
|
|||
305 | if intro is not None: |
|
|||
306 | self.intro = intro |
|
|||
307 | if self.intro: |
|
|||
308 | self.stdout.write(str(self.intro)+"\n") |
|
|||
309 | stop = None |
|
|||
310 | while not stop: |
|
|||
311 | if self.cmdqueue: |
|
|||
312 | line = self.cmdqueue.pop(0) |
|
|||
313 | else: |
|
|||
314 | self._ptcomp.ipy_completer.namespace = self.curframe_locals |
|
|||
315 | self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals |
|
|||
316 | try: |
|
|||
317 | line = self.pt_cli.run(reset_current_buffer=True).text |
|
|||
318 | except EOFError: |
|
|||
319 | line = 'EOF' |
|
|||
320 | line = self.precmd(line) |
|
|||
321 | stop = self.onecmd(line) |
|
|||
322 | stop = self.postcmd(stop, line) |
|
|||
323 | self.postloop() |
|
|||
324 | except Exception: |
|
|||
325 | raise |
|
|||
326 |
|
||||
327 |
|
||||
328 |
|
247 | |||
329 | def set_colors(self, scheme): |
|
248 | def set_colors(self, scheme): | |
330 | """Shorthand access to the color table scheme selector method.""" |
|
249 | """Shorthand access to the color table scheme selector method.""" |
@@ -42,6 +42,7 b' from IPython.core.autocall import ExitAutocall' | |||||
42 | from IPython.core.builtin_trap import BuiltinTrap |
|
42 | from IPython.core.builtin_trap import BuiltinTrap | |
43 | from IPython.core.events import EventManager, available_events |
|
43 | from IPython.core.events import EventManager, available_events | |
44 | from IPython.core.compilerop import CachingCompiler, check_linecache_ipython |
|
44 | from IPython.core.compilerop import CachingCompiler, check_linecache_ipython | |
|
45 | from IPython.core.debugger import Pdb | |||
45 | from IPython.core.display_trap import DisplayTrap |
|
46 | from IPython.core.display_trap import DisplayTrap | |
46 | from IPython.core.displayhook import DisplayHook |
|
47 | from IPython.core.displayhook import DisplayHook | |
47 | from IPython.core.displaypub import DisplayPublisher |
|
48 | from IPython.core.displaypub import DisplayPublisher | |
@@ -1584,6 +1585,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
1584 | # Things related to exception handling and tracebacks (not debugging) |
|
1585 | # Things related to exception handling and tracebacks (not debugging) | |
1585 | #------------------------------------------------------------------------- |
|
1586 | #------------------------------------------------------------------------- | |
1586 |
|
1587 | |||
|
1588 | debugger_cls = Pdb | |||
|
1589 | ||||
1587 | def init_traceback_handlers(self, custom_exceptions): |
|
1590 | def init_traceback_handlers(self, custom_exceptions): | |
1588 | # Syntax error handler. |
|
1591 | # Syntax error handler. | |
1589 | self.SyntaxTB = ultratb.SyntaxTB(color_scheme='NoColor') |
|
1592 | self.SyntaxTB = ultratb.SyntaxTB(color_scheme='NoColor') | |
@@ -1594,7 +1597,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
1594 | self.InteractiveTB = ultratb.AutoFormattedTB(mode = 'Plain', |
|
1597 | self.InteractiveTB = ultratb.AutoFormattedTB(mode = 'Plain', | |
1595 | color_scheme='NoColor', |
|
1598 | color_scheme='NoColor', | |
1596 | tb_offset = 1, |
|
1599 | tb_offset = 1, | |
1597 |
check_cache=check_linecache_ipython |
|
1600 | check_cache=check_linecache_ipython, | |
|
1601 | debugger_cls=self.debugger_cls) | |||
1598 |
|
1602 | |||
1599 | # The instance will store a pointer to the system-wide exception hook, |
|
1603 | # The instance will store a pointer to the system-wide exception hook, | |
1600 | # so that runtime code (such as magics) can access it. This is because |
|
1604 | # so that runtime code (such as magics) can access it. This is because |
@@ -809,7 +809,7 b' class VerboseTB(TBTools):' | |||||
809 |
|
809 | |||
810 | def __init__(self, color_scheme='Linux', call_pdb=False, ostream=None, |
|
810 | def __init__(self, color_scheme='Linux', call_pdb=False, ostream=None, | |
811 | tb_offset=0, long_header=False, include_vars=True, |
|
811 | tb_offset=0, long_header=False, include_vars=True, | |
812 | check_cache=None): |
|
812 | check_cache=None, debugger_cls = None): | |
813 | """Specify traceback offset, headers and color scheme. |
|
813 | """Specify traceback offset, headers and color scheme. | |
814 |
|
814 | |||
815 | Define how many frames to drop from the tracebacks. Calling it with |
|
815 | Define how many frames to drop from the tracebacks. Calling it with | |
@@ -830,6 +830,8 b' class VerboseTB(TBTools):' | |||||
830 | check_cache = linecache.checkcache |
|
830 | check_cache = linecache.checkcache | |
831 | self.check_cache = check_cache |
|
831 | self.check_cache = check_cache | |
832 |
|
832 | |||
|
833 | self.debugger_cls = debugger_cls or debugger.Pdb | |||
|
834 | ||||
833 | def format_records(self, records, last_unique, recursion_repeat): |
|
835 | def format_records(self, records, last_unique, recursion_repeat): | |
834 | """Format the stack frames of the traceback""" |
|
836 | """Format the stack frames of the traceback""" | |
835 | frames = [] |
|
837 | frames = [] | |
@@ -1217,7 +1219,7 b' class VerboseTB(TBTools):' | |||||
1217 |
|
1219 | |||
1218 | if force or self.call_pdb: |
|
1220 | if force or self.call_pdb: | |
1219 | if self.pdb is None: |
|
1221 | if self.pdb is None: | |
1220 |
self.pdb = |
|
1222 | self.pdb = self.debugger_cls( | |
1221 | self.color_scheme_table.active_scheme_name) |
|
1223 | self.color_scheme_table.active_scheme_name) | |
1222 | # the system displayhook may have changed, restore the original |
|
1224 | # the system displayhook may have changed, restore the original | |
1223 | # for pdb |
|
1225 | # for pdb | |
@@ -1278,7 +1280,7 b' class FormattedTB(VerboseTB, ListTB):' | |||||
1278 | def __init__(self, mode='Plain', color_scheme='Linux', call_pdb=False, |
|
1280 | def __init__(self, mode='Plain', color_scheme='Linux', call_pdb=False, | |
1279 | ostream=None, |
|
1281 | ostream=None, | |
1280 | tb_offset=0, long_header=False, include_vars=False, |
|
1282 | tb_offset=0, long_header=False, include_vars=False, | |
1281 | check_cache=None): |
|
1283 | check_cache=None, debugger_cls=None): | |
1282 |
|
1284 | |||
1283 | # NEVER change the order of this list. Put new modes at the end: |
|
1285 | # NEVER change the order of this list. Put new modes at the end: | |
1284 | self.valid_modes = ['Plain', 'Context', 'Verbose'] |
|
1286 | self.valid_modes = ['Plain', 'Context', 'Verbose'] | |
@@ -1287,7 +1289,7 b' class FormattedTB(VerboseTB, ListTB):' | |||||
1287 | VerboseTB.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb, |
|
1289 | VerboseTB.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb, | |
1288 | ostream=ostream, tb_offset=tb_offset, |
|
1290 | ostream=ostream, tb_offset=tb_offset, | |
1289 | long_header=long_header, include_vars=include_vars, |
|
1291 | long_header=long_header, include_vars=include_vars, | |
1290 | check_cache=check_cache) |
|
1292 | check_cache=check_cache, debugger_cls=debugger_cls) | |
1291 |
|
1293 | |||
1292 | # Different types of tracebacks are joined with different separators to |
|
1294 | # Different types of tracebacks are joined with different separators to | |
1293 | # form a single string. They are taken from this dict |
|
1295 | # form a single string. They are taken from this dict |
@@ -26,6 +26,7 b' from prompt_toolkit.styles import PygmentsStyle, DynamicStyle' | |||||
26 | from pygments.styles import get_style_by_name, get_all_styles |
|
26 | from pygments.styles import get_style_by_name, get_all_styles | |
27 | from pygments.token import Token |
|
27 | from pygments.token import Token | |
28 |
|
28 | |||
|
29 | from .debugger import TerminalPdb | |||
29 | from .pt_inputhooks import get_inputhook_func |
|
30 | from .pt_inputhooks import get_inputhook_func | |
30 | from .interactiveshell import get_default_editor, TerminalMagics |
|
31 | from .interactiveshell import get_default_editor, TerminalMagics | |
31 | from .ptutils import IPythonPTCompleter, IPythonPTLexer |
|
32 | from .ptutils import IPythonPTCompleter, IPythonPTLexer | |
@@ -43,6 +44,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
43 |
|
44 | |||
44 | pt_cli = None |
|
45 | pt_cli = None | |
45 | debugger_history = None |
|
46 | debugger_history = None | |
|
47 | debugger_cls = TerminalPdb | |||
46 |
|
48 | |||
47 | autoedit_syntax = Bool(False, |
|
49 | autoedit_syntax = Bool(False, | |
48 | help="auto editing of files with syntax errors.", |
|
50 | help="auto editing of files with syntax errors.", |
General Comments 0
You need to be logged in to leave comments.
Login now