##// END OF EJS Templates
Add history file to debugger....
Matthias Bussonnier -
Show More
@@ -1,18 +1,22 b''
1 import asyncio
1 import asyncio
2 import os
2 import sys
3 import sys
3 import threading
4 import threading
4
5
5 from IPython.core.debugger import Pdb
6 from IPython.core.debugger import Pdb
6
7
8
7 from IPython.core.completer import IPCompleter
9 from IPython.core.completer import IPCompleter
8 from .ptutils import IPythonPTCompleter
10 from .ptutils import IPythonPTCompleter
9 from .shortcuts import create_ipython_shortcuts
11 from .shortcuts import create_ipython_shortcuts
10 from . import embed
12 from . import embed
11
13
14 from pathlib import Path
12 from pygments.token import Token
15 from pygments.token import Token
13 from prompt_toolkit.shortcuts.prompt import PromptSession
16 from prompt_toolkit.shortcuts.prompt import PromptSession
14 from prompt_toolkit.enums import EditingMode
17 from prompt_toolkit.enums import EditingMode
15 from prompt_toolkit.formatted_text import PygmentsTokens
18 from prompt_toolkit.formatted_text import PygmentsTokens
19 from prompt_toolkit.history import InMemoryHistory, FileHistory
16
20
17 from prompt_toolkit import __version__ as ptk_version
21 from prompt_toolkit import __version__ as ptk_version
18 PTK3 = ptk_version.startswith('3.')
22 PTK3 = ptk_version.startswith('3.')
@@ -55,6 +59,17 b' class TerminalPdb(Pdb):'
55
59
56 self._ptcomp = IPythonPTCompleter(compl)
60 self._ptcomp = IPythonPTCompleter(compl)
57
61
62 # setup history only when we start pdb
63 if self.shell.debugger_history is None:
64 if self.shell.debugger_history_file is not None:
65
66 p = Path(self.shell.debugger_history_file).expanduser()
67 if not p.exists():
68 p.touch()
69 self.debugger_history = FileHistory(os.path.expanduser(str(p)))
70 else:
71 self.debugger_history = InMemoryHistory()
72
58 options = dict(
73 options = dict(
59 message=(lambda: PygmentsTokens(get_prompt_tokens())),
74 message=(lambda: PygmentsTokens(get_prompt_tokens())),
60 editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
75 editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
@@ -124,6 +124,10 b' class TerminalInteractiveShell(InteractiveShell):'
124 pt_app = None
124 pt_app = None
125 debugger_history = None
125 debugger_history = None
126
126
127 debugger_history_file = Unicode(
128 "~/.pdbhistory", help="File in which to store and read history"
129 ).tag(config=True)
130
127 simple_prompt = Bool(_use_simple_prompt,
131 simple_prompt = Bool(_use_simple_prompt,
128 help="""Use `raw_input` for the REPL, without completion and prompt colors.
132 help="""Use `raw_input` for the REPL, without completion and prompt colors.
129
133
@@ -566,7 +570,6 b' class TerminalInteractiveShell(InteractiveShell):'
566 self.init_term_title()
570 self.init_term_title()
567 self.keep_running = True
571 self.keep_running = True
568
572
569 self.debugger_history = InMemoryHistory()
570
573
571 def ask_exit(self):
574 def ask_exit(self):
572 self.keep_running = False
575 self.keep_running = False
General Comments 0
You need to be logged in to leave comments. Login now