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

Method pr

cmd2/history.py:91–116  ·  view source on GitHub ↗

Represent this item in a pretty fashion suitable for printing. If you pass verbose=True, script and expanded will be ignored :param idx: The 1-based index of this item in the history list :param script: True if formatting for a script (No item numbers) :param expand

(self, idx: int, script: bool = False, expanded: bool = False, verbose: bool = False)

Source from the content-addressed store, hash-verified

89 return self.statement.expanded_command_line
90
91 def pr(self, idx: int, script: bool = False, expanded: bool = False, verbose: bool = False) -> str:
92 """Represent this item in a pretty fashion suitable for printing.
93
94 If you pass verbose=True, script and expanded will be ignored
95
96 :param idx: The 1-based index of this item in the history list
97 :param script: True if formatting for a script (No item numbers)
98 :param expanded: True if expanded command line should be printed
99 :param verbose: True if expanded and raw should both appear when they are different
100 :return: pretty print string version of a HistoryItem
101 """
102 if verbose:
103 raw = self.raw.rstrip()
104 expanded_command = self.expanded
105
106 ret_str = self._listformat.format(idx, raw)
107 if raw != expanded_command:
108 ret_str += "\n" + self._ex_listformat.format(idx, expanded_command)
109 else:
110 ret_str = self.expanded if expanded else single_line_format(self.statement).rstrip()
111
112 # Display a numbered list if not writing to a script
113 if not script:
114 ret_str = self._listformat.format(idx, ret_str)
115
116 return ret_str
117
118 def to_dict(self) -> dict[str, Any]:
119 """Convert this HistoryItem into a dictionary for use in persistent JSON history files."""

Callers 4

do_historyMethod · 0.80
test_multiline_histitemFunction · 0.80

Calls 1

single_line_formatFunction · 0.85