diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-03-03 14:53:38 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-03-03 14:53:38 -0500 |
commit | 009cb87895c2e23521f2fe1b69252231fa010a5a (patch) | |
tree | d10fb3ae742fb20d3a9cbc6c0bad23da026d11d2 | |
parent | 46df1c127e11ac59706e6656543d06621fd7bc1e (diff) | |
download | cmd2-git-009cb87895c2e23521f2fe1b69252231fa010a5a.tar.gz |
Potential fixes for outstanding multi-line issues in history command
-rw-r--r-- | cmd2/cmd2.py | 12 | ||||
-rw-r--r-- | cmd2/constants.py | 1 | ||||
-rw-r--r-- | cmd2/history.py | 4 | ||||
-rw-r--r-- | cmd2/parsing.py | 6 |
4 files changed, 15 insertions, 8 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index c404ee1d..42cb58b4 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -302,7 +302,7 @@ class Cmd(cmd.Cmd): # Attributes used to configure the StatementParser, best not to change these at runtime multiline_commands = [] shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'} - terminators = [';'] + terminators = [constants.MULTILINE_TERMINATOR] # Attributes which are NOT dynamically settable at runtime allow_cli_args = True # Should arguments passed on the command-line be processed as commands? @@ -3256,7 +3256,10 @@ class Cmd(cmd.Cmd): fd, fname = tempfile.mkstemp(suffix='.txt', text=True) with os.fdopen(fd, 'w') as fobj: for command in history: - fobj.write('{}\n'.format(command)) + if command.statement.multiline_command: + fobj.write('{}\n'.format(command.expanded.rstrip())) + else: + fobj.write('{}\n'.format(command)) try: self.do_edit(fname) self.do_load(fname) @@ -3268,7 +3271,10 @@ class Cmd(cmd.Cmd): try: with open(os.path.expanduser(args.output_file), 'w') as fobj: for command in history: - fobj.write('{}\n'.format(command)) + if command.statement.multiline_command: + fobj.write('{}\n'.format(command.expanded.rstrip())) + else: + fobj.write('{}\n'.format(command)) plural = 's' if len(history) > 1 else '' self.pfeedback('{} command{} saved to {}'.format(len(history), plural, args.output_file)) except Exception as e: diff --git a/cmd2/constants.py b/cmd2/constants.py index 3c133b70..39115493 100644 --- a/cmd2/constants.py +++ b/cmd2/constants.py @@ -12,6 +12,7 @@ REDIRECTION_OUTPUT = '>' REDIRECTION_APPEND = '>>' REDIRECTION_CHARS = [REDIRECTION_PIPE, REDIRECTION_OUTPUT] REDIRECTION_TOKENS = [REDIRECTION_PIPE, REDIRECTION_OUTPUT, REDIRECTION_APPEND] +MULTILINE_TERMINATOR = ';' # Regular expression to match ANSI escape codes ANSI_ESCAPE_RE = re.compile(r'\x1b[^m]*m') diff --git a/cmd2/history.py b/cmd2/history.py index 26ff5d4d..45de3478 100644 --- a/cmd2/history.py +++ b/cmd2/history.py @@ -46,13 +46,13 @@ class HistoryItem(str): else: if script: # display without entry numbers - if expanded: + if expanded or self.statement.multiline_command: ret_str = self.expanded.rstrip() else: ret_str = str(self) else: # display a numbered list - if expanded: + 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, str(self).rstrip()) diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 070d3774..90484d76 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -191,8 +191,8 @@ class Statement(str): def expanded_command_line(self) -> str: """Contains command_and_args plus any ending terminator, suffix, and redirection chars""" rtn = self.command_and_args - if self.terminator: - rtn += self.terminator + if self.multiline_command: + rtn += constants.MULTILINE_TERMINATOR if self.suffix: rtn += ' ' + self.suffix @@ -240,7 +240,7 @@ class StatementParser: ): self.allow_redirection = allow_redirection if terminators is None: - self.terminators = [';'] + self.terminators = [constants.MULTILINE_TERMINATOR] else: self.terminators = terminators if multiline_commands is None: |