diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-14 23:08:28 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-14 23:08:28 -0400 |
commit | 37c67e598095382469dd0b3982a667bc9401a038 (patch) | |
tree | b4f6bd25881f92f47f835ee9c31b087eabcd6108 /cmd2 | |
parent | 2311acf725e46257808a653319ccac73003d4a49 (diff) | |
parent | 57ac00c5001dd39dff0fb7800bb8d530c320d7be (diff) | |
download | cmd2-git-37c67e598095382469dd0b3982a667bc9401a038.tar.gz |
Merge branch 'master' into deprecate_34
Diffstat (limited to 'cmd2')
-rw-r--r-- | cmd2/cmd2.py | 18 | ||||
-rw-r--r-- | cmd2/history.py | 31 |
2 files changed, 30 insertions, 19 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 226e0df7..7fcb38d6 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1908,13 +1908,17 @@ class Cmd(cmd.Cmd): :return: parsed command line as a Statement """ used_macros = [] - orig_line = line + orig_line = None # Continue until all macros are resolved while True: # Make sure all input has been read and convert it to a Statement statement = self._complete_statement(line) + # Save the fully entered line if this is the first loop iteration + if orig_line is None: + orig_line = statement.raw + # Check if this command matches a macro and wasn't already processed to avoid an infinite loop if statement.command in self.macros.keys() and statement.command not in used_macros: used_macros.append(statement.command) @@ -3478,11 +3482,13 @@ class Cmd(cmd.Cmd): if rl_type != RlType.NONE: last = None for item in history: - # readline only adds a single entry for multiple sequential identical commands - # so we emulate that behavior here - if item.raw != last: - readline.add_history(item.raw) - last = item.raw + # Break the command into its individual lines + for line in item.raw.splitlines(): + # readline only adds a single entry for multiple sequential identical lines + # so we emulate that behavior here + if line != last: + readline.add_history(line) + last = line # register a function to write history at save # if the history file is in plain text format from 0.9.12 or lower diff --git a/cmd2/history.py b/cmd2/history.py index bbeb9199..a61ab0d8 100644 --- a/cmd2/history.py +++ b/cmd2/history.py @@ -44,22 +44,27 @@ class HistoryItem(): :return: pretty print string version of a HistoryItem """ if verbose: - ret_str = self._listformat.format(self.idx, self.raw) + ret_str = self._listformat.format(self.idx, self.raw.rstrip()) if self.raw != self.expanded.rstrip(): - ret_str += self._ex_listformat.format(self.idx, self.expanded) + ret_str += self._ex_listformat.format(self.idx, self.expanded.rstrip()) else: - if script: - # display without entry numbers - if expanded or self.statement.multiline_command: - ret_str = self.expanded.rstrip() - else: - ret_str = self.raw.rstrip() + if expanded: + ret_str = self.expanded.rstrip() else: - # display a numbered list - if expanded or self.statement.multiline_command: - ret_str = self._listformat.format(self.idx, self.expanded.rstrip()) - else: - ret_str = self._listformat.format(self.idx, self.raw.rstrip()) + ret_str = self.raw.rstrip() + + # In non-verbose mode, display raw multiline commands on 1 line + if self.statement.multiline_command: + # This is an approximation and not meant to be a perfect piecing together of lines. + # All newlines will be converted to spaces, including the ones in quoted strings that + # are considered literals. Also if the final line starts with a terminator, then the + # terminator will have an extra space before it in the 1 line version. + ret_str = ret_str.replace('\n', ' ') + + # Display a numbered list if not writing to a script + if not script: + ret_str = self._listformat.format(self.idx, ret_str) + return ret_str |