monitor: Add `clear` command
v2 cover monitor: Add `clear` command
Add clear command in monitor, just like linux
terminal clear command do.
---
v2:
- Correct the ANSI escape sequence order.
- Add more detailed comment in code.
v1:
- Init commit, see:
https://lore.kernel.org/qemu-devel/[email protected]/
---
Alano Song (1):
monitor: Add clear command
hmp-commands.hx | 14 ++++++++++++++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 11 +++++++++++ 3 files changed, 26 insertions(+)
Signature · 1 line
2.43.0
PATCH v2 1/1 monitor: Add `clear` command
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.
--- hmp-commands.hx | 14 ++++++++++++++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 11 +++++++++++ 3 files changed, 26 insertions(+)
hmp-commands.hx +14 -0
@@ -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",
include/monitor/hmp.h +1 -0
@@ -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);
monitor/hmp-cmds.c +11 -0
@@ -218,6 +218,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" );
Signature · 1 line
2.43.0
Quoted 8 lines · * [email protected] ([email protected]) wrote:
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 linuxclearcommand 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]>
Thanks for fixing that.
Quoted 68 lines
--- hmp-commands.hx | 14 ++++++++++++++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 11 +++++++++++ 3 files changed, 26 insertions(+)hmp-commands.hx +14
-0@@ -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",include/monitor/hmp.h +1
-0@@ -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);monitor/hmp-cmds.c +11
-0@@ -218,6 +218,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" );Signature · 1 line
2.43.0
Signature · 4 lines
-----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/