##// END OF EJS Templates
Hook up command history and populate it from IPython's history DB
Thomas Kluyver -
Show More
@@ -1,5 +1,6 b''
1 from IPython.core.interactiveshell import InteractiveShell
1 from IPython.core.interactiveshell import InteractiveShell
2
2
3 from prompt_toolkit.history import InMemoryHistory
3 from prompt_toolkit.shortcuts import create_prompt_application
4 from prompt_toolkit.shortcuts import create_prompt_application
4 from prompt_toolkit.interface import CommandLineInterface
5 from prompt_toolkit.interface import CommandLineInterface
5 from prompt_toolkit.key_binding.manager import KeyBindingManager
6 from prompt_toolkit.key_binding.manager import KeyBindingManager
@@ -35,12 +36,23 b' class PTInteractiveShell(InteractiveShell):'
35 if (status != 'incomplete') and b.accept_action.is_returnable:
36 if (status != 'incomplete') and b.accept_action.is_returnable:
36 b.accept_action.validate_and_handle(event.cli, b)
37 b.accept_action.validate_and_handle(event.cli, b)
37 else:
38 else:
38 b.insert_text('\n' + (' ' * indent))
39 b.insert_text('\n' + (' ' * (indent or 0)))
40
41 # Pre-populate history from IPython's history database
42 history = InMemoryHistory()
43 last_cell = u""
44 for _, _, cell in self.history_manager.get_tail(self.history_load_length,
45 include_latest=True):
46 # Ignore blank lines and consecutive duplicates
47 cell = cell.rstrip()
48 if cell and (cell != last_cell):
49 history.append(cell)
39
50
40 app = create_prompt_application(multiline=True,
51 app = create_prompt_application(multiline=True,
41 lexer=PygmentsLexer(Python3Lexer),
52 lexer=PygmentsLexer(Python3Lexer),
42 get_prompt_tokens=self.get_prompt_tokens,
53 get_prompt_tokens=self.get_prompt_tokens,
43 key_bindings_registry=kbmanager.registry,
54 key_bindings_registry=kbmanager.registry,
55 history=history,
44 )
56 )
45
57
46 self.pt_cli = CommandLineInterface(app)
58 self.pt_cli = CommandLineInterface(app)
General Comments 0
You need to be logged in to leave comments. Login now