##// END OF EJS Templates
Add frame parameter to terminal debugger.
tillahoffmann -
Show More
@@ -1,82 +1,90 b''
1 1 from IPython.core.debugger import Pdb
2 2
3 3 from IPython.core.completer import IPCompleter
4 4 from .ptutils import IPythonPTCompleter
5 5
6 6 from prompt_toolkit.token import Token
7 7 from prompt_toolkit.shortcuts import create_prompt_application
8 8 from prompt_toolkit.interface import CommandLineInterface
9 9 from prompt_toolkit.enums import EditingMode
10 import sys
11
10 12
11 13 class TerminalPdb(Pdb):
12 14 def __init__(self, *args, **kwargs):
13 15 Pdb.__init__(self, *args, **kwargs)
14 16 self._ptcomp = None
15 17 self.pt_init()
16 18
17 19 def pt_init(self):
18 20 def get_prompt_tokens(cli):
19 21 return [(Token.Prompt, self.prompt)]
20 22
21 23 if self._ptcomp is None:
22 24 compl = IPCompleter(shell=self.shell,
23 25 namespace={},
24 26 global_namespace={},
25 27 use_readline=False,
26 28 parent=self.shell,
27 29 )
28 30 self._ptcomp = IPythonPTCompleter(compl)
29 31
30 32 self._pt_app = create_prompt_application(
31 33 editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
32 34 history=self.shell.debugger_history,
33 35 completer= self._ptcomp,
34 36 enable_history_search=True,
35 37 mouse_support=self.shell.mouse_support,
36 38 get_prompt_tokens=get_prompt_tokens
37 39 )
38 40 self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
39 41
40 42 def cmdloop(self, intro=None):
41 43 """Repeatedly issue a prompt, accept input, parse an initial prefix
42 44 off the received input, and dispatch to action methods, passing them
43 45 the remainder of the line as argument.
44 46
45 47 override the same methods from cmd.Cmd to provide prompt toolkit replacement.
46 48 """
47 49 if not self.use_rawinput:
48 50 raise ValueError('Sorry ipdb does not support use_rawinput=False')
49 51
50 52 self.preloop()
51 53
52 54 try:
53 55 if intro is not None:
54 56 self.intro = intro
55 57 if self.intro:
56 58 self.stdout.write(str(self.intro)+"\n")
57 59 stop = None
58 60 while not stop:
59 61 if self.cmdqueue:
60 62 line = self.cmdqueue.pop(0)
61 63 else:
62 64 self._ptcomp.ipy_completer.namespace = self.curframe_locals
63 65 self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
64 66 try:
65 67 line = self.pt_cli.run(reset_current_buffer=True).text
66 68 except EOFError:
67 69 line = 'EOF'
68 70 line = self.precmd(line)
69 71 stop = self.onecmd(line)
70 72 stop = self.postcmd(stop, line)
71 73 self.postloop()
72 74 except Exception:
73 75 raise
74 76
75 def set_trace():
76 TerminalPdb().set_trace()
77
78 def set_trace(frame=None):
79 """
80 Start debugging from `frame`.
81
82 If frame is not specified, debugging starts from caller's frame.
83 """
84 TerminalPdb().set_trace(frame or sys._getframe().f_back)
77 85
78 86
79 87 if __name__ == '__main__':
80 88 import pdb
81 89 pdb.Pdb = TerminalPdb
82 90 pdb.main()
General Comments 0
You need to be logged in to leave comments. Login now