Show More
@@ -3042,9 +3042,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
3042 | cell = raw_cell |
|
3042 | cell = raw_cell | |
3043 |
|
3043 | |||
3044 | # Store raw and processed history |
|
3044 | # Store raw and processed history | |
3045 | if store_history: |
|
3045 | if store_history and raw_cell.strip(" %") != "paste": | |
3046 | self.history_manager.store_inputs(self.execution_count, |
|
3046 | self.history_manager.store_inputs(self.execution_count, cell, raw_cell) | |
3047 | cell, raw_cell) |
|
|||
3048 | if not silent: |
|
3047 | if not silent: | |
3049 | self.logger.log(cell, raw_cell) |
|
3048 | self.logger.log(cell, raw_cell) | |
3050 |
|
3049 |
@@ -3,12 +3,10 b'' | |||||
3 | import asyncio |
|
3 | import asyncio | |
4 | import os |
|
4 | import os | |
5 | import sys |
|
5 | import sys | |
6 | import warnings |
|
|||
7 | from warnings import warn |
|
6 | from warnings import warn | |
8 |
|
7 | |||
9 | from IPython.core.async_helpers import get_asyncio_loop |
|
8 | from IPython.core.async_helpers import get_asyncio_loop | |
10 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC |
|
9 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC | |
11 | from IPython.utils import io |
|
|||
12 | from IPython.utils.py3compat import input |
|
10 | from IPython.utils.py3compat import input | |
13 | from IPython.utils.terminal import toggle_set_term_title, set_term_title, restore_term_title |
|
11 | from IPython.utils.terminal import toggle_set_term_title, set_term_title, restore_term_title | |
14 | from IPython.utils.process import abbrev_cwd |
|
12 | from IPython.utils.process import abbrev_cwd | |
@@ -32,7 +30,7 b' from prompt_toolkit.auto_suggest import AutoSuggestFromHistory' | |||||
32 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode |
|
30 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode | |
33 | from prompt_toolkit.filters import (HasFocus, Condition, IsDone) |
|
31 | from prompt_toolkit.filters import (HasFocus, Condition, IsDone) | |
34 | from prompt_toolkit.formatted_text import PygmentsTokens |
|
32 | from prompt_toolkit.formatted_text import PygmentsTokens | |
35 |
from prompt_toolkit.history import |
|
33 | from prompt_toolkit.history import History | |
36 | from prompt_toolkit.layout.processors import ConditionalProcessor, HighlightMatchingBracketProcessor |
|
34 | from prompt_toolkit.layout.processors import ConditionalProcessor, HighlightMatchingBracketProcessor | |
37 | from prompt_toolkit.output import ColorDepth |
|
35 | from prompt_toolkit.output import ColorDepth | |
38 | from prompt_toolkit.patch_stdout import patch_stdout |
|
36 | from prompt_toolkit.patch_stdout import patch_stdout | |
@@ -132,6 +130,43 b' def yapf_reformat_handler(text_before_cursor):' | |||||
132 | return text_before_cursor |
|
130 | return text_before_cursor | |
133 |
|
131 | |||
134 |
|
132 | |||
|
133 | class PtkHistoryAdapter(History): | |||
|
134 | """ | |||
|
135 | Prompt toolkit has it's own way of handling history, Where it assumes it can | |||
|
136 | Push/pull from history. | |||
|
137 | ||||
|
138 | """ | |||
|
139 | ||||
|
140 | def __init__(self, shell): | |||
|
141 | super().__init__() | |||
|
142 | self.shell = shell | |||
|
143 | self._refresh() | |||
|
144 | ||||
|
145 | def append_string(self, string): | |||
|
146 | # we rely on sql for that. | |||
|
147 | self._loaded = False | |||
|
148 | self._refresh() | |||
|
149 | ||||
|
150 | def _refresh(self): | |||
|
151 | if not self._loaded: | |||
|
152 | self._loaded_strings = list(self.load_history_strings()) | |||
|
153 | ||||
|
154 | def load_history_strings(self): | |||
|
155 | last_cell = "" | |||
|
156 | res = [] | |||
|
157 | for __, ___, cell in self.shell.history_manager.get_tail( | |||
|
158 | self.shell.history_load_length, include_latest=True | |||
|
159 | ): | |||
|
160 | # Ignore blank lines and consecutive duplicates | |||
|
161 | cell = cell.rstrip() | |||
|
162 | if cell and (cell != last_cell): | |||
|
163 | res.append(cell) | |||
|
164 | last_cell = cell | |||
|
165 | yield from res[::-1] | |||
|
166 | ||||
|
167 | def store_string(self, string: str) -> None: | |||
|
168 | pass | |||
|
169 | ||||
135 | class TerminalInteractiveShell(InteractiveShell): |
|
170 | class TerminalInteractiveShell(InteractiveShell): | |
136 | mime_renderers = Dict().tag(config=True) |
|
171 | mime_renderers = Dict().tag(config=True) | |
137 |
|
172 | |||
@@ -397,16 +432,9 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
397 | # Set up keyboard shortcuts |
|
432 | # Set up keyboard shortcuts | |
398 | key_bindings = create_ipython_shortcuts(self) |
|
433 | key_bindings = create_ipython_shortcuts(self) | |
399 |
|
434 | |||
|
435 | ||||
400 | # Pre-populate history from IPython's history database |
|
436 | # Pre-populate history from IPython's history database | |
401 |
history = |
|
437 | history = PtkHistoryAdapter(self) | |
402 | last_cell = u"" |
|
|||
403 | for __, ___, cell in self.history_manager.get_tail(self.history_load_length, |
|
|||
404 | include_latest=True): |
|
|||
405 | # Ignore blank lines and consecutive duplicates |
|
|||
406 | cell = cell.rstrip() |
|
|||
407 | if cell and (cell != last_cell): |
|
|||
408 | history.append_string(cell) |
|
|||
409 | last_cell = cell |
|
|||
410 |
|
438 | |||
411 | self._style = self._make_style_from_name_or_cls(self.highlighting_style) |
|
439 | self._style = self._make_style_from_name_or_cls(self.highlighting_style) | |
412 | self.style = DynamicStyle(lambda: self._style) |
|
440 | self.style = DynamicStyle(lambda: self._style) | |
@@ -586,7 +614,6 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
586 | def enable_win_unicode_console(self): |
|
614 | def enable_win_unicode_console(self): | |
587 | # Since IPython 7.10 doesn't support python < 3.6 and PEP 528, Python uses the unicode APIs for the Windows |
|
615 | # Since IPython 7.10 doesn't support python < 3.6 and PEP 528, Python uses the unicode APIs for the Windows | |
588 | # console by default, so WUC shouldn't be needed. |
|
616 | # console by default, so WUC shouldn't be needed. | |
589 | from warnings import warn |
|
|||
590 | warn("`enable_win_unicode_console` is deprecated since IPython 7.10, does not do anything and will be removed in the future", |
|
617 | warn("`enable_win_unicode_console` is deprecated since IPython 7.10, does not do anything and will be removed in the future", | |
591 | DeprecationWarning, |
|
618 | DeprecationWarning, | |
592 | stacklevel=2) |
|
619 | stacklevel=2) |
@@ -53,7 +53,7 b' class TerminalMagics(Magics):' | |||||
53 | self.shell.user_ns['pasted_block'] = b |
|
53 | self.shell.user_ns['pasted_block'] = b | |
54 | self.shell.using_paste_magics = True |
|
54 | self.shell.using_paste_magics = True | |
55 | try: |
|
55 | try: | |
56 | self.shell.run_cell(b) |
|
56 | self.shell.run_cell(b, store_history=True) | |
57 | finally: |
|
57 | finally: | |
58 | self.shell.using_paste_magics = False |
|
58 | self.shell.using_paste_magics = False | |
59 |
|
59 |
General Comments 0
You need to be logged in to leave comments.
Login now