From: "[email protected]" <[email protected]> The monitor screen can be cluttered after executing commands like `info qtree`. It is useful to have a command to clear current screen, just like linux `clear` command do.
This patch has been tested under monitors using stdio, vc, tcp socket, unix socket and serial interfaces. Signed-off-by: Alano Song <[email protected]> Reviewed-by: Dr. David Alan Gilbert <[email protected]> Signed-off-by: Dr. David Alan Gilbert <[email protected]> Message-ID: <[email protected]> Signed-off-by: Markus Armbruster <[email protected]> --- include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 11 +++++++++++ hmp-commands.hx | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index e222bea60c..9b66458d21 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -165,6 +165,7 @@ void hmp_trace_event(Monitor *mon, const QDict *qdict); void hmp_trace_file(Monitor *mon, const QDict *qdict); void hmp_info_trace_events(Monitor *mon, const QDict *qdict); void hmp_help(Monitor *mon, const QDict *qdict); +void hmp_clear(Monitor *mon, const QDict *qdict); void hmp_info_help(Monitor *mon, const QDict *qdict); void hmp_info_sync_profile(Monitor *mon, const QDict *qdict); void hmp_info_history(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index afa7b709a6..1b44d07c18 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -219,6 +219,17 @@ void hmp_help(Monitor *mon, const QDict *qdict) hmp_help_cmd(mon, qdict_get_try_str(qdict, "name")); } +void hmp_clear(Monitor *mon, const QDict *qdict) +{ + /* + * Send an ANSI escape sequence: + * "\x1b[H" - move cursor to top-left + * "\x1b[2J" - clear visible screen + * "\x1b[3J" - clear scrollback + */ + monitor_printf(mon, "\x1b[H\x1b[2J\x1b[3J"); +} + void hmp_info_help(Monitor *mon, const QDict *qdict) { hmp_help_cmd(mon, "info"); diff --git a/hmp-commands.hx b/hmp-commands.hx index f4a6eeda93..b806ec5635 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -20,6 +20,20 @@ SRST Show the help for all commands or just for command *cmd*. ERST + { + .name = "clear", + .args_type = "", + .params = "", + .help = "clear the monitor screen", + .cmd = hmp_clear, + .flags = "p", + }, + +SRST +``clear`` + Clear the monitor screen. +ERST + { .name = "commit", .args_type = "device:B", -- 2.54.0
