All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] monitor: Add `clear` command
@ 2026-04-18 13:39 AlanoSong
  2026-04-18 17:23 ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 7+ messages in thread
From: AlanoSong @ 2026-04-18 13:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: dave, pbonzini, Alano Song

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>
---
 hmp-commands.hx       | 14 ++++++++++++++
 include/monitor/hmp.h |  1 +
 monitor/hmp-cmds.c    |  5 +++++
 3 files changed, 20 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 5cc4788f12..95f9166732 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",
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 bc26b39d70..3e9485478e 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -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");
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] monitor: Add `clear` command
  2026-04-18 13:39 [PATCH] monitor: Add `clear` command AlanoSong
@ 2026-04-18 17:23 ` Dr. David Alan Gilbert
  2026-04-19  7:43   ` Alano Song
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Dr. David Alan Gilbert @ 2026-04-18 17:23 UTC (permalink / raw)
  To: AlanoSong; +Cc: qemu-devel, pbonzini

* AlanoSong@163.com (AlanoSong@163.com) 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.
> 
> Signed-off-by: Alano Song <AlanoSong@163.com>

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

Dave

> ---
>  hmp-commands.hx       | 14 ++++++++++++++
>  include/monitor/hmp.h |  1 +
>  monitor/hmp-cmds.c    |  5 +++++
>  3 files changed, 20 insertions(+)
> 
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 5cc4788f12..95f9166732 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",
> 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 bc26b39d70..3e9485478e 100644
> --- a/monitor/hmp-cmds.c
> +++ b/monitor/hmp-cmds.c
> @@ -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");
> -- 
> 2.43.0
> 
-- 
 -----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   |_______/


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re:Re: [PATCH] monitor: Add `clear` command
  2026-04-18 17:23 ` Dr. David Alan Gilbert
@ 2026-04-19  7:43   ` Alano Song
  2026-04-21 17:52     ` Dr. David Alan Gilbert
  2026-04-19  8:43   ` Paolo Bonzini
  2026-04-20 13:35   ` Alano Song
  2 siblings, 1 reply; 7+ messages in thread
From: Alano Song @ 2026-04-19  7:43 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: qemu-devel, pbonzini

[-- Attachment #1: Type: text/plain, Size: 3356 bytes --]

At 2026-04-19 01:23:46, "Dr. David Alan Gilbert" <dave@treblig.org> wrote:
>* AlanoSong@163.com (AlanoSong@163.com) 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.
>> 
>> Signed-off-by: Alano Song <AlanoSong@163.com>
>
>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.


>> ---
>>  hmp-commands.hx       | 14 ++++++++++++++
>>  include/monitor/hmp.h |  1 +
>>  monitor/hmp-cmds.c    |  5 +++++
>>  3 files changed, 20 insertions(+)
>> 
>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>> index 5cc4788f12..95f9166732 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",
>> 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 bc26b39d70..3e9485478e 100644
>> --- a/monitor/hmp-cmds.c
>> +++ b/monitor/hmp-cmds.c
>> @@ -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");
>> -- 
>> 2.43.0
>> 
>-- 
> -----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   |_______/

[-- Attachment #2: Type: text/html, Size: 4239 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] monitor: Add `clear` command
  2026-04-18 17:23 ` Dr. David Alan Gilbert
  2026-04-19  7:43   ` Alano Song
@ 2026-04-19  8:43   ` Paolo Bonzini
  2026-04-20 13:35   ` Alano Song
  2 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2026-04-19  8:43 UTC (permalink / raw)
  To: Dr. David Alan Gilbert, AlanoSong; +Cc: qemu-devel

On 4/18/26 19:23, Dr. David Alan Gilbert wrote:
> * AlanoSong@163.com (AlanoSong@163.com) 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.
>>
>> Signed-off-by: Alano Song <AlanoSong@163.com>
> 
> 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

> Dave
> 
>> ---
>>   hmp-commands.hx       | 14 ++++++++++++++
>>   include/monitor/hmp.h |  1 +
>>   monitor/hmp-cmds.c    |  5 +++++
>>   3 files changed, 20 insertions(+)
>>
>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>> index 5cc4788f12..95f9166732 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",
>> 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 bc26b39d70..3e9485478e 100644
>> --- a/monitor/hmp-cmds.c
>> +++ b/monitor/hmp-cmds.c
>> @@ -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");
>> -- 
>> 2.43.0
>>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] monitor: Add `clear` command
  2026-04-18 17:23 ` Dr. David Alan Gilbert
  2026-04-19  7:43   ` Alano Song
  2026-04-19  8:43   ` Paolo Bonzini
@ 2026-04-20 13:35   ` Alano Song
  2 siblings, 0 replies; 7+ messages in thread
From: Alano Song @ 2026-04-20 13:35 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: qemu-devel, pbonzini

[-- Attachment #1: Type: text/plain, Size: 3464 bytes --]

At 2026-04-19 01:23:46, "Dr. David Alan Gilbert" <dave@treblig.org> wrote:
>* AlanoSong@163.com (AlanoSong@163.com) 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.
>> 
>> Signed-off-by: Alano Song <AlanoSong@163.com>
>
>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.


>> ---
>>  hmp-commands.hx       | 14 ++++++++++++++
>>  include/monitor/hmp.h |  1 +
>>  monitor/hmp-cmds.c    |  5 +++++
>>  3 files changed, 20 insertions(+)
>> 
>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>> index 5cc4788f12..95f9166732 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",
>> 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 bc26b39d70..3e9485478e 100644
>> --- a/monitor/hmp-cmds.c
>> +++ b/monitor/hmp-cmds.c
>> @@ -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");
>> -- 
>> 2.43.0
>> 
>-- 
> -----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   |_______/

[-- Attachment #2: Type: text/html, Size: 4358 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] monitor: Add `clear` command
  2026-04-19  7:43   ` Alano Song
@ 2026-04-21 17:52     ` Dr. David Alan Gilbert
  2026-04-22 13:44       ` Alano Song
  0 siblings, 1 reply; 7+ messages in thread
From: Dr. David Alan Gilbert @ 2026-04-21 17:52 UTC (permalink / raw)
  To: Alano Song; +Cc: qemu-devel, pbonzini

* Alano Song (alanosong@163.com) wrote:
> At 2026-04-19 01:23:46, "Dr. David Alan Gilbert" <dave@treblig.org> wrote:
> >* AlanoSong@163.com (AlanoSong@163.com) 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.
> >> 
> >> Signed-off-by: Alano Song <AlanoSong@163.com>
> >
> >Does typing ctrl-l not do it for you in your terminal?
> >
> >Dave
> >

Hi Alano,

> 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:

> >> +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
> >> +}
> >> +
> >>  void hmp_info_help(Monitor *mon, const QDict *qdict)
> >>  {
> >>      hmp_help_cmd(mon, "info");
> >> -- 
> >> 2.43.0
> >> 
> >-- 
> > -----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   |_______/
-- 
 -----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   |_______/


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] monitor: Add `clear` command
  2026-04-21 17:52     ` Dr. David Alan Gilbert
@ 2026-04-22 13:44       ` Alano Song
  0 siblings, 0 replies; 7+ messages in thread
From: Alano Song @ 2026-04-22 13:44 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: qemu-devel, pbonzini

[-- Attachment #1: Type: text/plain, Size: 3775 bytes --]

At 2026-04-22 01:52:54, "Dr. David Alan Gilbert" <dave@treblig.org> wrote:
>* Alano Song (alanosong@163.com) wrote:
>> At 2026-04-19 01:23:46, "Dr. David Alan Gilbert" <dave@treblig.org> wrote:
>> >* AlanoSong@163.com (AlanoSong@163.com) 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.
>> >> 
>> >> Signed-off-by: Alano Song <AlanoSong@163.com>
>> >
>> >Does typing ctrl-l not do it for you in your terminal?
>> >
>> >Dave
>> >
>
>Hi Alano,
>
>> 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)
>


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


>Now to get to the magic line:
>
>> >> +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

>


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 :)


>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.


>> >> +}
>> >> +
>> >>  void hmp_info_help(Monitor *mon, const QDict *qdict)
>> >>  {
>> >>      hmp_help_cmd(mon, "info");
>> >> -- 
>> >> 2.43.0
>> >> 
>> >-- 
>> > -----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   |_______/
>-- 
> -----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   |_______/

[-- Attachment #2: Type: text/html, Size: 4662 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-04-22 13:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-18 13:39 [PATCH] monitor: Add `clear` command AlanoSong
2026-04-18 17:23 ` Dr. David Alan Gilbert
2026-04-19  7:43   ` Alano Song
2026-04-21 17:52     ` Dr. David Alan Gilbert
2026-04-22 13:44       ` Alano Song
2026-04-19  8:43   ` Paolo Bonzini
2026-04-20 13:35   ` Alano Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.