MCPcopy Index your code
hub / github.com/ipython/ipython / PtkHistoryAdapter

Class PtkHistoryAdapter

IPython/terminal/interactiveshell.py:170–205  ·  view source on GitHub ↗

Prompt toolkit has it's own way of handling history, Where it assumes it can Push/pull from history.

Source from the content-addressed store, hash-verified

168
169
170class PtkHistoryAdapter(History):
171 """
172 Prompt toolkit has it's own way of handling history, Where it assumes it can
173 Push/pull from history.
174
175 """
176
177 def __init__(self, shell):
178 super().__init__()
179 self.shell = shell
180 self._refresh()
181
182 def append_string(self, string):
183 # we rely on sql for that.
184 self._loaded = False
185 self._refresh()
186
187 def _refresh(self):
188 if not self._loaded:
189 self._loaded_strings = list(self.load_history_strings())
190
191 def load_history_strings(self):
192 last_cell = ""
193 res = []
194 for __, ___, cell in self.shell.history_manager.get_tail(
195 self.shell.history_load_length, include_latest=True
196 ):
197 # Ignore blank lines and consecutive duplicates
198 cell = cell.rstrip()
199 if cell and (cell != last_cell):
200 res.append(cell)
201 last_cell = cell
202 yield from res[::-1]
203
204 def store_string(self, string: str) -> None:
205 pass
206
207class TerminalInteractiveShell(InteractiveShell):
208 mime_renderers = Dict().tag(config=True)

Callers 2

test_llm_autosuggestionFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_llm_autosuggestionFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…