summaryrefslogtreecommitdiff
path: root/cmd2/history.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2019-02-09 18:39:17 -0700
committerkotfu <kotfu@kotfu.net>2019-02-09 18:39:17 -0700
commit3911335e5533405dd7f65195fe1f20bf3ac08ef8 (patch)
tree1aa2c2b19b3256ce55e145823fdda8dad984d08b /cmd2/history.py
parent321a8c72a48d227011177bb91006ed20607a1e44 (diff)
downloadcmd2-git-3911335e5533405dd7f65195fe1f20bf3ac08ef8.tar.gz
Added -x option to history command for #545
Diffstat (limited to 'cmd2/history.py')
-rw-r--r--cmd2/history.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/cmd2/history.py b/cmd2/history.py
index 0989b7db..ad4b23aa 100644
--- a/cmd2/history.py
+++ b/cmd2/history.py
@@ -14,7 +14,7 @@ from .parsing import Statement
class HistoryItem(str):
"""Class used to represent one command in the History list"""
listformat = ' {:>4} {}\n'
- ex_listformat = ' Ex: {}\n'
+ ex_listformat = ' {:>4}x {}\n'
def __new__(cls, statement: Statement):
"""Create a new instance of HistoryItem
@@ -32,15 +32,30 @@ class HistoryItem(str):
"""Return the command as run which includes shortcuts and aliases resolved plus any changes made in hooks"""
return self.statement.expanded_command_line
- def pr(self, verbose: bool) -> str:
+ def pr(self, script=False, expanded=False, verbose=False) -> str:
"""Represent a HistoryItem in a pretty fashion suitable for printing.
+ If you pass verbose=True, script and expanded will be ignored
+
:return: pretty print string version of a HistoryItem
"""
- ret_str = self.listformat.format(self.idx, str(self).rstrip())
- if verbose and self != self.expanded:
- ret_str += self.ex_listformat.format(self.expanded.rstrip())
-
+ if verbose:
+ ret_str = self.listformat.format(self.idx, str(self).rstrip())
+ if self != self.expanded:
+ ret_str += self.ex_listformat.format(self.idx, self.expanded.rstrip())
+ else:
+ if script:
+ # display without entry numbers
+ if expanded:
+ ret_str = self.expanded.rstrip()
+ else:
+ ret_str = str(self)
+ else:
+ # display a numbered list
+ if expanded:
+ ret_str = self.listformat.format(self.idx, self.expanded.rstrip())
+ else:
+ ret_str = self.listformat.format(self.idx, str(self).rstrip())
return ret_str