]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
monitor: Add `clear` command
authorAlanoSong@163.com <AlanoSong@163.com>
Mon, 4 May 2026 17:49:14 +0000 (18:49 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 5 May 2026 11:53:03 +0000 (13:53 +0200)
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 <AlanoSong@163.com>
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
Message-ID: <20260504174914.122607-5-dave@treblig.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
hmp-commands.hx
include/monitor/hmp.h
monitor/hmp-cmds.c

index f4a6eeda931cbd1ac4fc4b475524c5dc88f9de62..b806ec5635c4cdc88821e2de01afe5f4183cec6e 100644 (file)
@@ -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",
index e222bea60cd8487585575a8c9c6b37718bd0675f..9b66458d21ff8a382744618b133a893ee7d93f50 100644 (file)
@@ -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);
index afa7b709a6cdde0173afc46689ef7de02d267444..1b44d07c18db9038c17991de6e13a466d2a87c5e 100644 (file)
@@ -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");