public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrei Pikas <gdb@mail.api.win>
To: gdb-patches@sourceware.org
Cc: aburgess@redhat.com, Andrei Pikas <gdb@mail.api.win>
Subject: [PATCH v4 (fix formatting and revert cli_colors to original state)] Add style tui-current-line command to colorize TUI current line.
Date: Mon, 18 Jul 2022 22:11:18 +0300	[thread overview]
Message-ID: <20220718191118.57311-1-gdb@mail.api.win> (raw)
In-Reply-To: <87r12iqyr7.fsf@redhat.com>

Adds the ability to customize the colors of the current line of code in TUI.
This may be desirable when code highlighting is enabled. Because higlighted
keywords in dark blue color are indistinguishable from a black background
(which is the default inverse color for a white terminal).
Here is a screenshot of old and new behavior
https://drive.google.com/file/d/1RnrDjvdsnV8y_lrnavs6wvQ6lXbtjRup/view
---
 gdb/NEWS            |  4 ++++
 gdb/cli/cli-style.c | 14 ++++++++++++++
 gdb/cli/cli-style.h |  3 +++
 gdb/doc/gdb.texinfo |  3 +++
 gdb/tui/tui-io.c    | 44 ++++++++++++++++++++++++++++++++++++++++----
 gdb/tui/tui-win.c   |  1 +
 6 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 1178a37017e..03c8f53738d 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -41,6 +41,10 @@
 
 * New commands
 
+set style tui-current-line foreground COLOR
+set style tui-current-line background COLOR
+  Control the styling of the currently executing line of code.
+
 maintenance set ignore-prologue-end-flag on|off
 maintenance show ignore-prologue-end-flag
   This setting, which is off by default, controls whether GDB ignores the
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index 3fd85f4aa86..eaaf6913fb1 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -101,6 +101,11 @@ cli_style_option tui_active_border_style ("tui-active-border",
 
 /* See cli-style.h.  */
 
+cli_style_option tui_current_line_style ("tui-current-line",
+					 ui_file_style::NONE);
+
+/* See cli-style.h.  */
+
 cli_style_option metadata_style ("metadata", ui_file_style::DIM);
 
 /* See cli-style.h.  */
@@ -446,6 +451,15 @@ TUI window that does have the focus."),
 						&style_show_list,
 						true);
 
+  tui_current_line_style.add_setshow_commands (no_class, _("\
+TUI current line display styling.\n\
+Configure TUI current line colors\n\
+The \"tui-current-line\" style is used when GDB displays the current line of \
+code."),
+						&style_set_list,
+						&style_show_list,
+						true);
+
   version_style.add_setshow_commands (no_class, _("\
 Version string display styling.\n\
 Configure colors used to display the GDB version string."),
diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h
index f69df47098c..745e530c6a9 100644
--- a/gdb/cli/cli-style.h
+++ b/gdb/cli/cli-style.h
@@ -122,6 +122,9 @@ extern cli_style_option tui_border_style;
 /* The border style of a TUI window that does have the focus.  */
 extern cli_style_option tui_active_border_style;
 
+/* The style of a reverse mode for current line in TUI window.  */
+extern cli_style_option tui_current_line_style;
+
 /* The style to use for the GDB version string.  */
 extern cli_style_option version_style;
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7a4e337d15b..d3a45087217 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -26642,6 +26642,9 @@ general styling to @value{GDBN}.  @xref{TUI Configuration}.
 Control the styling of the active TUI border; that is, the TUI window
 that has the focus.
 
+@item tui-current-line
+Control the styling of the currently executing line of code.
+
 @end table
 
 @node Numbers
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 22c234a0dc2..343e8a1ff2c 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -35,6 +35,7 @@
 #include "tui/tui-out.h"
 #include "ui-out.h"
 #include "cli-out.h"
+#include "cli/cli-style.h"
 #include <fcntl.h>
 #include <signal.h>
 #ifdef __MINGW32__
@@ -351,6 +352,22 @@ tui_apply_style (WINDOW *w, ui_file_style style)
   last_style = style;
 }
 
+/* Reads style which have been set by command "set style tui-current-line" into
+   STYLE and returns true.
+   Returns false and leaves STYLE untouched if tui-current-line style
+   isn't set. */
+
+static bool
+get_custom_current_line_style (ui_file_style *style)
+{
+  ui_file_style current_line_style = tui_current_line_style.style ();
+  if (current_line_style.is_default ())
+    return false;
+
+  *style = current_line_style;
+  return true;
+}
+
 /* Apply an ANSI escape sequence from BUF to W.  BUF must start with
    the ESC character.  If BUF does not start with an ANSI escape,
    return 0.  Otherwise, apply the sequence if it is recognized, or
@@ -392,10 +409,12 @@ apply_ansi_escape (WINDOW *w, const char *buf)
 	  ui_file_style::color fg = style.get_foreground ();
 	  style.set_fg (bg);
 	  style.set_bg (fg);
-	}
 
-      /* Enable A_REVERSE.  */
-      style.set_reverse (true);
+	  /* Enable A_REVERSE.  */
+	  style.set_reverse (true);
+	}
+      else if (!get_custom_current_line_style (&style))
+	style.set_reverse (true);
     }
 
   tui_apply_style (w, style);
@@ -410,17 +429,19 @@ tui_set_reverse_mode (WINDOW *w, bool reverse)
   ui_file_style style = last_style;
 
   reverse_mode_p = reverse;
-  style.set_reverse (reverse);
 
   if (reverse)
     {
       reverse_save_bg = style.get_background ();
       reverse_save_fg = style.get_foreground ();
+      if (!get_custom_current_line_style (&style))
+        style.set_reverse (reverse);
     }
   else
     {
       style.set_bg (reverse_save_bg);
       style.set_fg (reverse_save_fg);
+      style.set_reverse (reverse);
     }
 
   tui_apply_style (w, style);
@@ -448,6 +469,9 @@ tui_puts (const char *string, WINDOW *w)
   if (w == nullptr)
     w = TUI_CMD_WIN->handle.get ();
 
+  attr_t w_attrs = 0;
+  short w_pair = 0;
+
   while (true)
     {
       const char *next = strpbrk (string, "\n\1\2\033\t");
@@ -472,6 +496,13 @@ tui_puts (const char *string, WINDOW *w)
 	  break;
 
 	case '\n':
+	  if (wattr_get (w, &w_attrs, &w_pair, nullptr) == OK)
+	    /* Apply current style till the end of line. */
+	    wchgat (w, -1, w_attrs, w_pair, nullptr);
+	  do_tui_putc (w, c);
+	  ++next;
+	  break;
+
 	case '\t':
 	  do_tui_putc (w, c);
 	  ++next;
@@ -497,6 +528,11 @@ tui_puts (const char *string, WINDOW *w)
       string = next;
     }
 
+  if (wattr_get (w, &w_attrs, &w_pair, nullptr) == OK)
+    /* Apply current style till the end of line. */
+    wchgat (w, -1, w_attrs, w_pair, nullptr);
+
+
   if (TUI_CMD_WIN != nullptr && w == TUI_CMD_WIN->handle.get ())
     update_cmdwin_start_line ();
 }
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 31b6606636a..d03b12984ad 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -1197,4 +1197,5 @@ the line numbers and uses less horizontal space."),
 
   tui_border_style.changed.attach (tui_rehighlight_all, "tui-win");
   tui_active_border_style.changed.attach (tui_rehighlight_all, "tui-win");
+  tui_current_line_style.changed.attach (tui_refresh_all_win, "tui-win");
 }
-- 
2.34.1


  reply	other threads:[~2022-07-18 19:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-09 19:05 [PATCH] Add style tui-reverse " Andrei Pikas
2022-07-09 19:10 ` Eli Zaretskii
2022-07-09 20:20   ` [PATCH] Add style tui-cursorline " Andrei Pikas
2022-07-10  5:03     ` Eli Zaretskii
2022-07-10 10:10       ` [PATCH v2 (mentions of reverse mode eliminated)] " Andrei Pikas
2022-07-10 10:19         ` Eli Zaretskii
2022-07-15 19:40         ` Tom Tromey
2022-07-15 22:06           ` Andrei Pikas
2022-07-18 14:16             ` Andrew Burgess
2022-07-18 15:32               ` Andrei Pikas
2022-07-18 18:12               ` Tom Tromey
2022-07-15 22:49           ` [PATCH v3] Add style tui-current-line " Andrei Pikas
2022-07-16  5:35             ` Eli Zaretskii
2022-07-18 14:30             ` Andrew Burgess
2022-07-18 19:11               ` Andrei Pikas [this message]
2022-07-18 19:14                 ` [PATCH v4 (fix formatting and revert cli_colors to original state)] " Eli Zaretskii
2022-07-18 19:16                   ` Andrei Pikas

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=20220718191118.57311-1-gdb@mail.api.win \
    --to=gdb@mail.api.win \
    --cc=aburgess@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).