In order to support more user-friendly command list file, this commit adds the support for: + comment lines: line staring by '#' are ignored + escaped enf-of-line: line with trailing ' \' are continued on next one
For eol: we impose a space before the '\' in order not to trigger the escape if the '\' is for example at the end of a value in a 'key=value' sequence. Althought it does not have any real interest in interactive mode, the prompt is adapted when in that case. Signed-off-by: Damien Hedde <damien.he...@greensocs.com> --- python/qemu/aqmp/qmp_shell.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/qemu/aqmp/qmp_shell.py b/python/qemu/aqmp/qmp_shell.py index dd38ef8a13..64cd31dcd6 100644 --- a/python/qemu/aqmp/qmp_shell.py +++ b/python/qemu/aqmp/qmp_shell.py @@ -188,6 +188,7 @@ def __init__(self, address: SocketAddrT, self._greeting: Optional[QMPMessage] = None self._completer = QMPCompleter() self._transmode = False + self._escaped_eol = False self._actions: List[QMPMessage] = [] self._histfile = os.path.join(os.path.expanduser('~'), '.qmp-shell_history') @@ -385,6 +386,8 @@ def prompt(self) -> str: """ if not sys.stdin.isatty(): return "" + if self._escaped_eol: + return '> ' if self._transmode: return 'TRANS> ' return '(QEMU) ' @@ -397,6 +400,11 @@ def read_exec_command(self) -> bool: """ try: cmdline = input(self.prompt) + self._escaped_eol = True + while cmdline[-2:] == ' \\': + #only remove the trailing '\', keep the space + cmdline = cmdline[:-1] + input(self.prompt) + self._escaped_eol = False except EOFError: print() return False @@ -406,6 +414,10 @@ def read_exec_command(self) -> bool: print(event) return True + if cmdline[0] == '#': + #consider these lines as comments + return True + if self.raise_error: resp = self._execute_cmd(cmdline) if resp and 'error' in resp: -- 2.35.1