summaryrefslogtreecommitdiff
path: root/cmd2/history.py
diff options
context:
space:
mode:
authorxNinjaKittyx <xNinjaKittyx@users.noreply.github.com>2020-12-15 17:21:33 -0800
committerxNinjaKittyx <xNinjaKittyx@users.noreply.github.com>2020-12-15 18:20:13 -0800
commit9aa54a5b27468d61337528cb1e1b5b9b11a80978 (patch)
tree567693115cc101efb9254a96d96d80e9f9ccd557 /cmd2/history.py
parent03c65c60b39e369958b056c5c844d36d515c8a63 (diff)
downloadcmd2-git-ci_improvements.tar.gz
Adds pre-commit config to run various lintersci_improvements
This ads black, isort, pyupgrade, and flake8 to pre-commit-config.yaml There are also some small changes to travis.yml and tasks.py to reduce some repeated configurations that should be consolidated into setup.cfg. Most other changes are automated by the linter scripts.
Diffstat (limited to 'cmd2/history.py')
-rw-r--r--cmd2/history.py13
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: