diff options
Diffstat (limited to 'cmd2/history.py')
-rw-r--r-- | cmd2/history.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/cmd2/history.py b/cmd2/history.py index 60a071fb..6c75434b 100644 --- a/cmd2/history.py +++ b/cmd2/history.py @@ -13,8 +13,9 @@ from .parsing import Statement @attr.s(frozen=True) -class HistoryItem(): +class HistoryItem: """Class used to represent one command in the history list""" + _listformat = ' {:>4} {}' _ex_listformat = ' {:>4}x {}' @@ -90,6 +91,7 @@ class History(list): Developers interested in accessing previously entered commands can use this class to gain access to the historical record. """ + def __init__(self, seq=()) -> None: super().__init__(seq) self.session_start_index = 0 @@ -223,7 +225,7 @@ class History(list): if include_persisted: result = self[:end] else: - result = self[self.session_start_index:end] + result = self[self.session_start_index : end] elif start is not None: # there was no separator so it's either a positive or negative integer result = [self[start]] @@ -232,7 +234,7 @@ class History(list): if include_persisted: result = self[:] else: - result = self[self.session_start_index:] + result = self[self.session_start_index :] return result def str_search(self, search: str, include_persisted: bool = False) -> List[HistoryItem]: @@ -242,6 +244,7 @@ class History(list): :param include_persisted: if True, then search full history including persisted history :return: a list of history items, or an empty list if the string was not found """ + def isin(history_item): """filter function for string search of history""" sloppy = utils.norm_fold(search) @@ -249,7 +252,7 @@ class History(list): inexpanded = sloppy in utils.norm_fold(history_item.expanded) return inraw or inexpanded - search_list = self if include_persisted else self[self.session_start_index:] + search_list = self if include_persisted else self[self.session_start_index :] return [item for item in search_list if isin(item)] def regex_search(self, regex: str, include_persisted: bool = False) -> List[HistoryItem]: @@ -268,7 +271,7 @@ class History(list): """filter function for doing a regular expression search of history""" return finder.search(hi.raw) or finder.search(hi.expanded) - search_list = self if include_persisted else self[self.session_start_index:] + search_list = self if include_persisted else self[self.session_start_index :] return [itm for itm in search_list if isin(itm)] def truncate(self, max_length: int) -> None: |