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.
| 154 | |
| 155 | |
| 156 | class 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 | |
| 193 | class Cmd2Lexer(Lexer): |
no outgoing calls
no test coverage detected
searching dependent graphs…