[4/4] Use command style in cmd_show_list

Message ID 20250112-submit-help-list-style-title-v1-4-9457a2686440@tromey.com
State New
Headers
Series More command styling changes |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom Tromey Jan. 12, 2025, 12:04 p.m. UTC
  cmd_show_list is a bit funny because it shows partial command names --
for a command like "show abc xyz", it will only show "abc xyz".

Nevertheless, I think it makes some sense to highlight these with the
command style.  That is what this patch does.
---
 gdb/auto-load.c       |  4 ++--
 gdb/cli/cli-setshow.c | 15 ++++++++++-----
 gdb/remote.c          |  3 ++-
 3 files changed, 14 insertions(+), 8 deletions(-)
  

Patch

diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index a8f3a8d5fdd474b190a2f419f93487594019a883..71bbae4fc1d436c7ee593a47122f1e5145eef43f 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -1472,7 +1472,7 @@  info_auto_load_cmd (const char *args, int from_tty)
   struct ui_out *uiout = current_uiout;
 
   ui_out_emit_tuple tuple_emitter (uiout, "infolist");
-
+  const ui_file_style cmd_style = command_style.style ();
   for (list = *auto_load_info_cmdlist_get (); list != NULL; list = list->next)
     {
       ui_out_emit_tuple option_emitter (uiout, "option");
@@ -1480,7 +1480,7 @@  info_auto_load_cmd (const char *args, int from_tty)
       gdb_assert (!list->is_prefix ());
       gdb_assert (list->type == not_set_cmd);
 
-      uiout->field_string ("name", list->name);
+      uiout->field_string ("name", list->name, cmd_style);
       uiout->text (":  ");
       cmd_func (list, auto_load_info_scripts_pattern_nl, from_tty);
     }
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index bcc793b3148035ae825696f31c42bb3811656eb7..b03d20cdb63b2a0528e886e3c33c06da549660f4 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -27,6 +27,7 @@ 
 #include "cli/cli-decode.h"
 #include "cli/cli-cmds.h"
 #include "cli/cli-setshow.h"
+#include "cli/cli-style.h"
 #include "cli/cli-utils.h"
 
 /* Return true if the change of command parameter should be notified.  */
@@ -681,6 +682,7 @@  cmd_show_list (struct cmd_list_element *list, int from_tty)
   struct ui_out *uiout = current_uiout;
 
   ui_out_emit_tuple tuple_emitter (uiout, "showlist");
+  const ui_file_style cmd_style = command_style.style ();
   for (; list != NULL; list = list->next)
     {
       /* We skip show command aliases to avoid showing duplicated values.  */
@@ -701,15 +703,18 @@  cmd_show_list (struct cmd_list_element *list, int from_tty)
 	{
 	  ui_out_emit_tuple option_emitter (uiout, "option");
 
-	  if (list->prefix != nullptr)
+	  if (!uiout->is_mi_like_p () && list->prefix != nullptr)
 	    {
 	      /* If we find a prefix, output it (with "show " skipped).  */
 	      std::string prefixname = list->prefix->prefixname ();
-	      prefixname = (!list->prefix->is_prefix () ? ""
-			    : strstr (prefixname.c_str (), "show ") + 5);
-	      uiout->text (prefixname);
+	      if (startswith (prefixname, "show "))
+		prefixname = prefixname.substr (5);
+	      /* In non-MI mode, we include the full name here.  */
+	      prefixname += list->name;
+	      uiout->field_string ("name", prefixname, cmd_style);
 	    }
-	  uiout->field_string ("name", list->name);
+	  else
+	    uiout->field_string ("name", list->name, cmd_style);
 	  uiout->text (":  ");
 	  if (list->type == show_cmd)
 	    do_show_command (NULL, from_tty, list);
diff --git a/gdb/remote.c b/gdb/remote.c
index 79d91d6251ab1b0ba6c314b022c188c36fbc455c..1aff6ab54d315ee900534fd101794b7a73474018 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -15582,6 +15582,7 @@  show_remote_cmd (const char *args, int from_tty)
   struct ui_out *uiout = current_uiout;
 
   ui_out_emit_tuple tuple_emitter (uiout, "showlist");
+  const ui_file_style cmd_style = command_style.style ();
   for (; list != NULL; list = list->next)
     if (strcmp (list->name, "Z-packet") == 0)
       continue;
@@ -15593,7 +15594,7 @@  show_remote_cmd (const char *args, int from_tty)
       {
 	ui_out_emit_tuple option_emitter (uiout, "option");
 
-	uiout->field_string ("name", list->name);
+	uiout->field_string ("name", list->name, cmd_style);
 	uiout->text (":  ");
 	if (list->type == show_cmd)
 	  do_show_command (NULL, from_tty, list);