MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / truncate

Method truncate

cmd2/history.py:314–326  ·  view source on GitHub ↗

Truncate the length of the history, dropping the oldest items if necessary. :param max_length: the maximum length of the history, if negative, all history items will be deleted :return: nothing

(self, max_length: int)

Source from the content-addressed store, hash-verified

312 return self._build_result_dictionary(start, len(self), isin)
313
314 def truncate(self, max_length: int) -> None:
315 """Truncate the length of the history, dropping the oldest items if necessary.
316
317 :param max_length: the maximum length of the history, if negative, all history
318 items will be deleted
319 :return: nothing
320 """
321 if max_length <= 0:
322 # remove all history
323 del self[:]
324 elif len(self) > max_length:
325 last_element = len(self) - max_length
326 del self[0:last_element]
327
328 def _build_result_dictionary(
329 self, start: int, end: int, filter_func: Callable[[HistoryItem], bool] | None = None

Callers 4

_persist_historyMethod · 0.80
test_history_max_lengthFunction · 0.80

Calls

no outgoing calls

Tested by 3

test_history_max_lengthFunction · 0.64