Skip to contentSkip to conversation

monitor: Add `clear` command

PATCH Superseded [email protected] 3 participants 7 messages Apr 18 – Apr 22

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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    |  5 +++++
 3 files changed, 20 insertions(+)
hmp-commands.hx +14 -0
index 5cc4788f12..95f9166732 100644
@@ -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
index e222bea60c..9b66458d21 100644
@@ -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 +5 -0
index bc26b39d70..3e9485478e 100644
@@ -218,6 +218,11 @@ 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)
+{
+    monitor_printf(mon, "\x1b[3J\x1b[2J\x1b[H");
+}
+
 void hmp_info_help(Monitor *mon, const QDict *qdict)
 {
     hmp_help_cmd(mon, "info");
Signature · 1 line
2.43.0
#1 lore raw
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 linux clear command do.

This patch has been tested under monitors using stdio, vc, tcp socket, unix socket and serial interfaces.

Does typing ctrl-l not do it for you in your terminal?

Dave

Quoted 62 lines
---
 hmp-commands.hx       | 14 ++++++++++++++
 include/monitor/hmp.h |  1 +
 monitor/hmp-cmds.c    |  5 +++++
 3 files changed, 20 insertions(+)
hmp-commands.hx +14 -0
index 5cc4788f12..95f9166732 100644
@@ -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
index e222bea60c..9b66458d21 100644
@@ -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 +5 -0
index bc26b39d70..3e9485478e 100644
@@ -218,6 +218,11 @@ 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)
+{
+    monitor_printf(mon, "\x1b[3J\x1b[2J\x1b[H");
+}
+
 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   |_______/
#2 lore raw
Quoted 11 lines · Dr. David Alan Gilbert
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 linux clear command do.

This patch has been tested under monitors using stdio, vc, tcp socket, unix socket and serial interfaces.

Does typing ctrl-l not do it for you in your terminal?

Yeah, we should add support for Ctrl-L to the non-terminal backends independent of this. However, backends such as socket do not use readline so they also don't support it right now.

Paolo

Quoted 64 lines

Dave

Quoted 62 lines
---
  hmp-commands.hx       | 14 ++++++++++++++
  include/monitor/hmp.h |  1 +
  monitor/hmp-cmds.c    |  5 +++++
  3 files changed, 20 insertions(+)
hmp-commands.hx +14 -0
index 5cc4788f12..95f9166732 100644
@@ -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
index e222bea60c..9b66458d21 100644
@@ -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 +5 -0
index bc26b39d70..3e9485478e 100644
@@ -218,6 +218,11 @@ 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)
+{
+    monitor_printf(mon, "\x1b[3J\x1b[2J\x1b[H");
+}
+
  void hmp_info_help(Monitor *mon, const QDict *qdict)
  {
      hmp_help_cmd(mon, "info");
Signature · 1 line
2.43.0
author
#3 lore raw
In reply to Dr. David Alan Gilbert
Quoted 5 lines · Dr. David Alan Gilbert
Quoted 4 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 linux clear command do.

Quoted 9 lines
Quoted 4 lines

This patch has been tested under monitors using stdio, vc, tcp socket, unix socket and serial interfaces.

Does typing ctrl-l not do it for you in your terminal?

Dave

Yes, you are correct that ctrl-l provides basic screen clear, but the new clear command clears both visible screen and scrollback buffer, just like clear command does on my Ubuntu terminal.

I still believe that this patch is useful:
1) Many linux users like me instinctively type clear when we want to tidy up the terminal.
2) Not everyone is aware of or remembers the ctrl-l shortcut. A typed command is more discoverable, especially for new users or those who don't use terminal shortcuts regularly.

Quoted 67 lines
Quoted 62 lines
---
 hmp-commands.hx       | 14 ++++++++++++++
 include/monitor/hmp.h |  1 +
 monitor/hmp-cmds.c    |  5 +++++
 3 files changed, 20 insertions(+)
hmp-commands.hx +14 -0
index 5cc4788f12..95f9166732 100644
@@ -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
index e222bea60c..9b66458d21 100644
@@ -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 +5 -0
index bc26b39d70..3e9485478e 100644
@@ -218,6 +218,11 @@ 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)
+{
+    monitor_printf(mon, "\x1b[3J\x1b[2J\x1b[H");
+}
+
 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   |_______/
#4 lore raw
Quoted 9 lines · * Alano Song ([email protected]) wrote:
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 7 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 linux clear command do.

This patch has been tested under monitors using stdio, vc, tcp socket, unix socket and serial interfaces.

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

Does typing ctrl-l not do it for you in your terminal?

Dave

Hi Alano,

Quoted 10 lines

Yes, you are correct that ctrl-l provides basic screen clear, but the new clear command clears both visible screen and scrollback buffer, just like clear command does on my Ubuntu terminal.

I still believe that this patch is useful:
1) Many linux users like me instinctively type clear when we want to tidy up the terminal.
2) Not everyone is aware of or remembers the ctrl-l shortcut. A typed command is more discoverable, especially for new users or those who don't use terminal shortcuts regularly.

OK, mainly because of the difference with the scrollback buffer which I see is different. (Ctrl-l is a great one to know, it works in almost everything, not just qemu, it's a basic ASCII control code going back about 60 years)

Now to get to the magic line:

Quoted 3 lines
Quoted 3 lines

monitor/hmp-cmds.c void hmp_help(Monitor *mon, const QDict *qdict) · line 223

Quoted 3 lines
monitor/hmp-cmds.c +3 -0
+void hmp_clear(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "\x1b[3J\x1b[2J\x1b[H");

Firstly it would be great to comment this; as I read it, this is:
clear scrollback
clear screen
cursor back to top-left

But, this has a problem - for me on both mate-terminal and terminator (but not konsole), this doesn't completely clear the scrollback; it clears most of the scrollback, but leaves about one page; my guess is what happens here is you clear the scrollback, but then the current screen goes into it after/when you clear it.

Looking at the output of the ncurses 'clear' command:

dg@dalek:~$ clear|xxd -g 1
00000000: 1b 5b 48 1b 5b 32 4a 1b 5b 33 4a                 .[H.[2J.[3J

it's got them in the opposite order, cursor, clear screen, clear scrollback and that's fine in both mate-terminal/terminator & konsole.
(This is Fedora 44 with vte291-0.84.0-1.fc44.x86_64 being used by mate-terminal). [I can't tell you if that's a bug in one or both of the terminals]

So please, flip the output around, and add a comment.

Thanks,

Dave

Quoted 13 lines
Quoted 13 lines
Quoted 8 lines
monitor/hmp-cmds.c +2 -0
+}
+
 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   |_______/
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   |_______/
author
#5 lore raw
Quoted 30 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Alano Song ([email protected]) wrote:
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 7 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 linux clear command do.

This patch has been tested under monitors using stdio, vc, tcp socket, unix socket and serial interfaces.

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

Does typing ctrl-l not do it for you in your terminal?

Dave

Hi Alano,

Quoted 10 lines

Yes, you are correct that ctrl-l provides basic screen clear, but the new clear command clears both visible screen and scrollback buffer, just like clear command does on my Ubuntu terminal.

I still believe that this patch is useful:
1) Many linux users like me instinctively type clear when we want to tidy up the terminal.
2) Not everyone is aware of or remembers the ctrl-l shortcut. A typed command is more discoverable, especially for new users or those who don't use terminal shortcuts regularly.

Quoted 5 lines

OK, mainly because of the difference with the scrollback buffer which I see is different. (Ctrl-l is a great one to know, it works in almost everything, not just qemu, it's a basic ASCII control code going back about 60 years)

Hi, Dr.Gilbert,
Thanks for sharing that, got it :)

Quoted 19 lines

Now to get to the magic line:

Quoted 3 lines
Quoted 3 lines

monitor/hmp-cmds.c void hmp_help(Monitor *mon, const QDict *qdict) · line 223

Quoted 3 lines
monitor/hmp-cmds.c +3 -0
+void hmp_clear(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "\x1b[3J\x1b[2J\x1b[H");

Firstly it would be great to comment this; as I read it, this is:
clear scrollback
clear screen
cursor back to top-left

But, this has a problem - for me on both mate-terminal and terminator (but not konsole), this doesn't completely clear the scrollback; it clears most of the scrollback, but leaves about one page; my guess is what happens here is you clear the scrollback, but then the current screen goes into it after/when you clear it.

Quoted 6 lines

Looking at the output of the ncurses 'clear' command:

dg@dalek:~$ clear|xxd -g 1
00000000: 1b 5b 48 1b 5b 32 4a 1b 5b 33 4a                 .[H.[2J.[3J

You are right, the command order on my ubuntu24.04 is the same with you:

alano@alano:~/code$ clear | xxd -g 1
00000000: 1b 5b 48 1b 5b 32 4a 1b 5b 33 4a                 .[H.[2J.[3J

So I will correct the command order sent in patch :)

Quoted 11 lines

it's got them in the opposite order, cursor, clear screen, clear scrollback and that's fine in both mate-terminal/terminator & konsole.
(This is Fedora 44 with vte291-0.84.0-1.fc44.x86_64 being used by mate-terminal). [I can't tell you if that's a bug in one or both of the terminals]

So please, flip the output around, and add a comment.

Thanks,

Dave

I will add comment in code and help info in v2 patch.

Best Regards,
Alano.

Quoted 18 lines
Quoted 13 lines
Quoted 13 lines
Quoted 8 lines
monitor/hmp-cmds.c +2 -0
+}
+
 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   |_______/
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   |_______/
author
#6 lore raw
In reply to Dr. David Alan Gilbert
Quoted 5 lines · Dr. David Alan Gilbert
Quoted 4 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 linux clear command do.

Quoted 9 lines
Quoted 4 lines

This patch has been tested under monitors using stdio, vc, tcp socket, unix socket and serial interfaces.

Does typing ctrl-l not do it for you in your terminal?

Dave

Yes, you are correct that ctrl-l provides basic screen clear, but the new clear command clears both visible screen and scrollback buffer, just like clear command does on my Ubuntu terminal.

I still believe that this patch is useful:
1) Many linux users like me instinctively type clear, when we want to tidy up the terminal.
2) Not everyone is aware of or remembers the ctrl-l shortcut. A typed command is more discoverable, especially for new users or those who don't use terminal shortcuts regularly.

Best Regards,
Alano.

// Re-send, it seems that the previous reply email is not visible in the mail list.

Quoted 67 lines
Quoted 62 lines
---
 hmp-commands.hx       | 14 ++++++++++++++
 include/monitor/hmp.h |  1 +
 monitor/hmp-cmds.c    |  5 +++++
 3 files changed, 20 insertions(+)
hmp-commands.hx +14 -0
index 5cc4788f12..95f9166732 100644
@@ -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
index e222bea60c..9b66458d21 100644
@@ -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 +5 -0
index bc26b39d70..3e9485478e 100644
@@ -218,6 +218,11 @@ 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)
+{
+    monitor_printf(mon, "\x1b[3J\x1b[2J\x1b[H");
+}
+
 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   |_______/