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