MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / Cmd2History

Class Cmd2History

cmd2/pt_utils.py:156–190  ·  view source on GitHub ↗

A non-persistent, in-memory history buffer for prompt-toolkit. This class serves as the backing store for UI history navigation (e.g., arrowing through previous commands). It explicitly avoids handling persistence, deferring all permanent storage logic to the cmd2 application.

Source from the content-addressed store, hash-verified

154
155
156class Cmd2History(History):
157 """A non-persistent, in-memory history buffer for prompt-toolkit.
158
159 This class serves as the backing store for UI history navigation (e.g., arrowing
160 through previous commands). It explicitly avoids handling persistence,
161 deferring all permanent storage logic to the cmd2 application.
162 """
163
164 def __init__(self, history_strings: Iterable[str] | None = None) -> None:
165 """Initialize the instance."""
166 super().__init__()
167
168 if history_strings:
169 for string in history_strings:
170 self.append_string(string)
171
172 # Mark that self._loaded_strings is populated.
173 self._loaded = True
174
175 def append_string(self, string: str) -> None:
176 """Override to filter our consecutive duplicates."""
177 # History is sorted newest to oldest, so we compare to the first element.
178 if string and (not self._loaded_strings or self._loaded_strings[0] != string):
179 super().append_string(string)
180
181 def store_string(self, string: str) -> None:
182 """No-op: Persistent history data is stored in cmd_app.history."""
183
184 def load_history_strings(self) -> Iterable[str]:
185 """Yield strings from newest to oldest."""
186 yield from self._loaded_strings
187
188 def clear(self) -> None:
189 """Clear the UI history navigation data."""
190 self._loaded_strings.clear()
191
192
193class Cmd2Lexer(Lexer):

Callers 1

_create_main_sessionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…