Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/2] Introduce ui_out::field_check_mark
Date: Fri, 09 May 2025 14:18:50 -0600	[thread overview]
Message-ID: <20250509-emoji-check-mark-v1-1-63b6c52411f3@adacore.com> (raw)
In-Reply-To: <20250509-emoji-check-mark-v1-0-63b6c52411f3@adacore.com>

This adds a new ui_out method, field_check_mark.  This method is to be
used to indicate the "current" or "selected" row in a table.  This
patch updates all the relevant tables to call this method.  No change
should be expected.
---
 gdb/ada-tasks.c         |  5 +----
 gdb/inferior.c          |  6 +-----
 gdb/linux-fork.c        |  5 +----
 gdb/progspace.c         |  6 +-----
 gdb/target-connection.c |  6 ++----
 gdb/thread.c            |  6 +-----
 gdb/ui-out.c            |  9 +++++++++
 gdb/ui-out.h            | 13 +++++++++++++
 8 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 259512377f085423d4feda1a8a67e409109179a2..2f152ec3581f1076110df2ca149a2add5a825e9e 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -1163,10 +1163,7 @@ print_ada_task_info (struct ui_out *uiout,
 
       /* Print a star if this task is the current task (or the task
 	 currently selected).  */
-      if (task_info->ptid == inferior_ptid)
-	uiout->field_string ("current", "*");
-      else
-	uiout->field_skip ("current");
+      uiout->field_check_mark ("current", task_info->ptid == inferior_ptid);
 
       /* Print the task number.  */
       uiout->field_signed ("id", taskno);
diff --git a/gdb/inferior.c b/gdb/inferior.c
index e8a28cd2a0e1a4f76946d4fc9c1abdfab08b5d3e..221dbce73d6721f5ed883745c0474e78d94c405d 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -598,11 +598,7 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
 
       ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
-      if (inf == current_inf)
-	uiout->field_string ("current", "*");
-      else
-	uiout->field_skip ("current");
-
+      uiout->field_check_mark ("current", inf == current_inf);
       uiout->field_signed ("number", inf->num);
 
       /* Because target_pid_to_str uses the current inferior,
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 338ba032a0e75862d449b9c02c3c61cfc5492dbe..dc50391b22a0ba2d5728d7ae5a4505a73d864fd9 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -849,10 +849,7 @@ print_checkpoints (struct ui_out *uiout, inferior *req_inf, fork_info *req_fi)
 
 	  ui_out_emit_tuple tuple_emitter (uiout, nullptr);
 
-	  if (is_current && cur_inf == inf)
-	    uiout->field_string ("current", "*");
-	  else
-	    uiout->field_skip ("current");
+	  uiout->field_check_mark ("current", is_current && cur_inf == inf);
 
 	  if (print_inf)
 	    uiout->field_fmt ("id", "%d.%d", inf->num, fi.num);
diff --git a/gdb/progspace.c b/gdb/progspace.c
index eda63790aec9169724119c766b7e4c72da3cb550..7f1b0652516f53bd0a69e88fb409887d8639e4c5 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -305,11 +305,7 @@ print_program_space (struct ui_out *uiout, int requested)
 
       ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
-      if (pspace == current_program_space)
-	uiout->field_string ("current", "*");
-      else
-	uiout->field_skip ("current");
-
+      uiout->field_check_mark ("current", pspace == current_program_space);
       uiout->field_signed ("id", pspace->num);
 
       if (pspace->exec_filename () != nullptr)
diff --git a/gdb/target-connection.c b/gdb/target-connection.c
index 60d7732b56e465ac6fda1164846302e1b9167456..69e5765959ef6bf0bfbc2fb482f5a26fa1a03c79 100644
--- a/gdb/target-connection.c
+++ b/gdb/target-connection.c
@@ -126,10 +126,8 @@ print_connection (struct ui_out *uiout, const char *requested_connections)
 
       ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
-      if (current_inferior ()->process_target () == t)
-	uiout->field_string ("current", "*");
-      else
-	uiout->field_skip ("current");
+      uiout->field_check_mark ("current",
+			       current_inferior ()->process_target () == t);
 
       uiout->field_signed ("number", t->connection_number);
 
diff --git a/gdb/thread.c b/gdb/thread.c
index b659463ef0246992a5290c1eb3b1175094a2e826..2ce94a01efbdfdfb2587d90a160f716171fd63c6 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1122,11 +1122,7 @@ do_print_thread (ui_out *uiout, const char *requested_threads,
 
   if (!uiout->is_mi_like_p ())
     {
-      if (tp == current_thread)
-	uiout->field_string ("current", "*");
-      else
-	uiout->field_skip ("current");
-
+      uiout->field_check_mark ("current", tp == current_thread);
       uiout->field_string ("id-in-tg", print_thread_id (tp));
     }
 
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 106a896c07fdadeae6c902a5bd541f81900c6453..a45a7af20d69170fb3ecac62f3f0345395bd88c2 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -557,6 +557,15 @@ ui_out::field_fmt (const char *fldname, const ui_file_style &style,
   va_end (args);
 }
 
+void
+ui_out::field_check_mark (const char *fldname, bool value)
+{
+  if (value)
+    field_string (fldname, get_check_mark ());
+  else
+    field_skip (fldname);
+}
+
 void
 ui_out::call_do_message (const ui_file_style &style, const char *format,
 			 ...)
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 1796e9c9eb3439422a767603d2799f4a7c167cf2..11d12024c2c15dd203a1df9d62eec72039a94c5e 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -206,6 +206,11 @@ class ui_out
 		  const char *format, ...)
     ATTRIBUTE_PRINTF (4, 5);
 
+  /* This is used when a table has a "current" field or the like.  If
+     VALUE is true, a check mark of some kind is emitted for the
+     field.  If VALUE is false, the field is skipped instead.  */
+  void field_check_mark (const char *fldname, bool value);
+
   void spaces (int numspaces) { do_spaces (numspaces); }
   void text (const char *string) { do_text (string); }
   void text (const std::string &string) { text (string.c_str ()); }
@@ -374,6 +379,14 @@ class ui_out
 				   double, double) = 0;
   virtual void do_progress_end () = 0;
 
+  /* Return the appropriate check-mark string.  */
+  virtual const char *get_check_mark ()
+  {
+    /* The default is "*" because that's what was done
+       historically.  */
+    return "*";
+  }
+
   /* Set as not MI-like by default.  It is overridden in subclasses if
      necessary.  */
 

-- 
2.49.0


  reply	other threads:[~2025-05-09 20:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-09 20:18 [PATCH 0/2] Use check-mark for current row of CLI table Tom Tromey
2025-05-09 20:18 ` Tom Tromey [this message]
2025-05-14  2:10   ` [PATCH 1/2] Introduce ui_out::field_check_mark Kevin Buettner
2025-05-09 20:18 ` [PATCH 2/2] Allow check-mark to be changed for CLI Tom Tromey
2025-05-10  6:23   ` Eli Zaretskii
2025-05-10  6:32   ` Eli Zaretskii
2025-05-16 14:18     ` Tom Tromey
2025-05-16 16:09       ` Eli Zaretskii
2025-05-23 15:00         ` Kévin Le Gouguec
2025-05-23 15:42           ` Eli Zaretskii
2025-06-11 13:53           ` Tom Tromey
2025-05-14 15:41   ` Andrew Burgess
2025-05-16 14:20     ` Tom Tromey
2025-05-16 16:16       ` Eli Zaretskii
2025-06-25 19:11         ` Pedro Alves
2025-06-26  5:51           ` Eli Zaretskii
2025-06-26 10:35             ` Pedro Alves
2025-06-26 12:32               ` Eli Zaretskii
2025-06-30 23:51                 ` Pedro Alves
2025-06-30 23:58                   ` Pedro Alves
2025-05-19 12:54       ` Andrew Burgess
2025-06-20 16:22   ` Pedro Alves
2025-06-24 16:58     ` Tom Tromey
2025-06-25 10:05       ` Pedro Alves
2025-06-25 15:43         ` Tom Tromey
2025-06-25 17:21           ` Pedro Alves
2025-06-27 16:17             ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250509-emoji-check-mark-v1-1-63b6c52411f3@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox