public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add style tui-reverse command to colorize TUI current line.
@ 2022-07-09 19:05 Andrei Pikas
  2022-07-09 19:10 ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Andrei Pikas @ 2022-07-09 19:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrei Pikas

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/1doYNdKRlEjsROUaP8DbanV4bBiam7EQl/view
---
 gdb/NEWS            |  4 ++++
 gdb/cli/cli-style.c | 34 ++++++++++++++++++++++++++++++++++
 gdb/cli/cli-style.h |  3 +++
 gdb/doc/gdb.texinfo |  3 +++
 gdb/tui/tui-io.c    | 36 ++++++++++++++++++++++++++++++++----
 gdb/tui/tui-win.c   |  1 +
 6 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 1178a37017e..bf5b3436b49 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -41,6 +41,10 @@
 
 * New commands
 
+set style tui-reverse foreground COLOR
+set style tui-reverse 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..3dc9721548f 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -54,6 +54,28 @@ static const char * const cli_colors[] = {
   "magenta",
   "cyan",
   "white",
+  "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
+  "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33",
+  "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
+  "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
+  "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72",
+  "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85",
+  "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98",
+  "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109",
+  "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120",
+  "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131",
+  "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142",
+  "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153",
+  "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164",
+  "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175",
+  "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186",
+  "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197",
+  "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208",
+  "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219",
+  "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230",
+  "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241",
+  "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252",
+  "253", "254", "255",
   nullptr
 };
 
@@ -101,6 +123,10 @@ cli_style_option tui_active_border_style ("tui-active-border",
 
 /* See cli-style.h.  */
 
+cli_style_option tui_reverse_style ("tui-reverse", ui_file_style::NONE);
+
+/* See cli-style.h.  */
+
 cli_style_option metadata_style ("metadata", ui_file_style::DIM);
 
 /* See cli-style.h.  */
@@ -446,6 +472,14 @@ TUI window that does have the focus."),
 						&style_show_list,
 						true);
 
+  tui_reverse_style.add_setshow_commands (no_class, _("\
+TUI reverse mode display styling.\n\
+Configure TUI reverse mode colors\n\
+The \"tui-reverse\" 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..b147f76b766 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_reverse_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..493acfd5c76 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-reverse
+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..8a470d4bbf4 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,17 @@ tui_apply_style (WINDOW *w, ui_file_style style)
   last_style = style;
 }
 
+static bool
+get_custom_reverse_style (ui_file_style *style)
+{
+  ui_file_style reverse_style = tui_reverse_style.style();
+  if (reverse_style.is_default())
+    return false;
+
+  *style = reverse_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 +404,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_reverse_style (&style))
+        style.set_reverse (true);
     }
 
   tui_apply_style (w, style);
@@ -410,17 +424,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_reverse_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 +464,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 +491,12 @@ tui_puts (const char *string, WINDOW *w)
 	  break;
 
 	case '\n':
+          if (wattr_get (w, &w_attrs, &w_pair, nullptr) == OK)
+            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 +522,9 @@ tui_puts (const char *string, WINDOW *w)
       string = next;
     }
 
+  if (wattr_get (w, &w_attrs, &w_pair, nullptr) == OK)
+    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..ec098e202d2 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_reverse_style.changed.attach (tui_refresh_all_win, "tui-win");
 }
-- 
2.34.1


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

* Re: [PATCH] Add style tui-reverse command to colorize TUI current line.
  2022-07-09 19:05 [PATCH] Add style tui-reverse command to colorize TUI current line Andrei Pikas
@ 2022-07-09 19:10 ` Eli Zaretskii
  2022-07-09 20:20   ` [PATCH] Add style tui-cursorline " Andrei Pikas
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2022-07-09 19:10 UTC (permalink / raw)
  To: Andrei Pikas; +Cc: gdb-patches, gdb

> From: Andrei Pikas <gdb@mail.api.win>
> Date: Sat,  9 Jul 2022 22:05:45 +0300
> Cc: Andrei Pikas <gdb@mail.api.win>
> 
> 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/1doYNdKRlEjsROUaP8DbanV4bBiam7EQl/view
> ---
>  gdb/NEWS            |  4 ++++
>  gdb/cli/cli-style.c | 34 ++++++++++++++++++++++++++++++++++
>  gdb/cli/cli-style.h |  3 +++
>  gdb/doc/gdb.texinfo |  3 +++
>  gdb/tui/tui-io.c    | 36 ++++++++++++++++++++++++++++++++----
>  gdb/tui/tui-win.c   |  1 +
>  6 files changed, 77 insertions(+), 4 deletions(-)

The documentation parts are okay, but I wonder why call this
"tu-reverse" when it is intended for the current line.  Why not
"tui-current-line" or somesuch?

Thanks.

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

* [PATCH] Add style tui-cursorline command to colorize TUI current line.
  2022-07-09 19:10 ` Eli Zaretskii
@ 2022-07-09 20:20   ` Andrei Pikas
  2022-07-10  5:03     ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Andrei Pikas @ 2022-07-09 20:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Eli Zaretskii, Andrei Pikas

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/1BbgNwpFa0DvKX0K9UAd48dEgtn8aChXP/view
---
 gdb/NEWS            |  4 ++++
 gdb/cli/cli-style.c | 35 +++++++++++++++++++++++++++++++++++
 gdb/cli/cli-style.h |  3 +++
 gdb/doc/gdb.texinfo |  3 +++
 gdb/tui/tui-io.c    | 38 ++++++++++++++++++++++++++++++++++----
 gdb/tui/tui-win.c   |  1 +
 6 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 1178a37017e..646c36ce032 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -41,6 +41,10 @@
 
 * New commands
 
+set style tui-cursorline foreground COLOR
+set style tui-cursorline 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..3a453cbd5d1 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -54,6 +54,28 @@ static const char * const cli_colors[] = {
   "magenta",
   "cyan",
   "white",
+  "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
+  "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33",
+  "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
+  "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
+  "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72",
+  "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85",
+  "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98",
+  "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109",
+  "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120",
+  "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131",
+  "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142",
+  "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153",
+  "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164",
+  "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175",
+  "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186",
+  "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197",
+  "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208",
+  "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219",
+  "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230",
+  "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241",
+  "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252",
+  "253", "254", "255",
   nullptr
 };
 
@@ -101,6 +123,10 @@ cli_style_option tui_active_border_style ("tui-active-border",
 
 /* See cli-style.h.  */
 
+cli_style_option tui_cursorline_style ("tui-cursorline", ui_file_style::NONE);
+
+/* See cli-style.h.  */
+
 cli_style_option metadata_style ("metadata", ui_file_style::DIM);
 
 /* See cli-style.h.  */
@@ -446,6 +472,15 @@ TUI window that does have the focus."),
 						&style_show_list,
 						true);
 
+  tui_cursorline_style.add_setshow_commands (no_class, _("\
+TUI reverse mode display styling.\n\
+Configure TUI reverse mode colors\n\
+The \"tui-cursorline\" 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..2b10814d18c 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_cursorline_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..427dfeaa254 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-cursorline
+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..7b8c59efdcf 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,17 @@ tui_apply_style (WINDOW *w, ui_file_style style)
   last_style = style;
 }
 
+static bool
+get_custom_cursorline_style (ui_file_style *style)
+{
+  ui_file_style cursorline_style = tui_cursorline_style.style();
+  if (cursorline_style.is_default())
+    return false;
+
+  *style = cursorline_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 +404,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_cursorline_style (&style))
+        style.set_reverse (true);
     }
 
   tui_apply_style (w, style);
@@ -410,17 +424,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_cursorline_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 +464,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 +491,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 +523,10 @@ 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..f80809d6732 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_cursorline_style.changed.attach (tui_refresh_all_win, "tui-win");
 }
-- 
2.34.1


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

* Re: [PATCH] Add style tui-cursorline command to colorize TUI current line.
  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
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2022-07-10  5:03 UTC (permalink / raw)
  To: Andrei Pikas; +Cc: gdb-patches, gdb

> From: Andrei Pikas <gdb@mail.api.win>
> Cc: Eli Zaretskii <eliz@gnu.org>,
> 	Andrei Pikas <gdb@mail.api.win>
> Date: Sat,  9 Jul 2022 23:20:42 +0300
> 
> 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/1BbgNwpFa0DvKX0K9UAd48dEgtn8aChXP/view
> ---
>  gdb/NEWS            |  4 ++++
>  gdb/cli/cli-style.c | 35 +++++++++++++++++++++++++++++++++++
>  gdb/cli/cli-style.h |  3 +++
>  gdb/doc/gdb.texinfo |  3 +++
>  gdb/tui/tui-io.c    | 38 ++++++++++++++++++++++++++++++++++----
>  gdb/tui/tui-win.c   |  1 +
>  6 files changed, 80 insertions(+), 4 deletions(-)

Thanks.

> +  tui_cursorline_style.add_setshow_commands (no_class, _("\
> +TUI reverse mode display styling.\n\
> +Configure TUI reverse mode colors\n\
> +The \"tui-cursorline\" style is used when GDB displays the current line of \
> +code."),

This still mentions "reverse mode" for some reason.

The documentation parts are OK.

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

* [PATCH v2 (mentions of reverse mode eliminated)] Add style tui-cursorline command to colorize TUI current line.
  2022-07-10  5:03     ` Eli Zaretskii
@ 2022-07-10 10:10       ` Andrei Pikas
  2022-07-10 10:19         ` Eli Zaretskii
  2022-07-15 19:40         ` Tom Tromey
  0 siblings, 2 replies; 17+ messages in thread
From: Andrei Pikas @ 2022-07-10 10:10 UTC (permalink / raw)
  To: gdb-patches; +Cc: Eli Zaretskii, Andrei Pikas

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/1BbgNwpFa0DvKX0K9UAd48dEgtn8aChXP/view
---
 gdb/NEWS            |  4 ++++
 gdb/cli/cli-style.c | 35 +++++++++++++++++++++++++++++++++++
 gdb/cli/cli-style.h |  3 +++
 gdb/doc/gdb.texinfo |  3 +++
 gdb/tui/tui-io.c    | 38 ++++++++++++++++++++++++++++++++++----
 gdb/tui/tui-win.c   |  1 +
 6 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 1178a37017e..646c36ce032 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -41,6 +41,10 @@
 
 * New commands
 
+set style tui-cursorline foreground COLOR
+set style tui-cursorline 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..77843cb5fb1 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -54,6 +54,28 @@ static const char * const cli_colors[] = {
   "magenta",
   "cyan",
   "white",
+  "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
+  "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33",
+  "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
+  "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
+  "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72",
+  "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85",
+  "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98",
+  "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109",
+  "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120",
+  "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131",
+  "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142",
+  "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153",
+  "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164",
+  "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175",
+  "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186",
+  "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197",
+  "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208",
+  "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219",
+  "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230",
+  "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241",
+  "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252",
+  "253", "254", "255",
   nullptr
 };
 
@@ -101,6 +123,10 @@ cli_style_option tui_active_border_style ("tui-active-border",
 
 /* See cli-style.h.  */
 
+cli_style_option tui_cursorline_style ("tui-cursorline", ui_file_style::NONE);
+
+/* See cli-style.h.  */
+
 cli_style_option metadata_style ("metadata", ui_file_style::DIM);
 
 /* See cli-style.h.  */
@@ -446,6 +472,15 @@ TUI window that does have the focus."),
 						&style_show_list,
 						true);
 
+  tui_cursorline_style.add_setshow_commands (no_class, _("\
+TUI cursor line display styling.\n\
+Configure TUI cursor line colors\n\
+The \"tui-cursorline\" 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..2b10814d18c 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_cursorline_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..427dfeaa254 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-cursorline
+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..7b8c59efdcf 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,17 @@ tui_apply_style (WINDOW *w, ui_file_style style)
   last_style = style;
 }
 
+static bool
+get_custom_cursorline_style (ui_file_style *style)
+{
+  ui_file_style cursorline_style = tui_cursorline_style.style();
+  if (cursorline_style.is_default())
+    return false;
+
+  *style = cursorline_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 +404,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_cursorline_style (&style))
+        style.set_reverse (true);
     }
 
   tui_apply_style (w, style);
@@ -410,17 +424,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_cursorline_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 +464,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 +491,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 +523,10 @@ 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..f80809d6732 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_cursorline_style.changed.attach (tui_refresh_all_win, "tui-win");
 }
-- 
2.34.1


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

* Re: [PATCH v2 (mentions of reverse mode eliminated)] Add style tui-cursorline command to colorize TUI current line.
  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
  1 sibling, 0 replies; 17+ messages in thread
From: Eli Zaretskii @ 2022-07-10 10:19 UTC (permalink / raw)
  To: Andrei Pikas; +Cc: gdb-patches, gdb

> From: Andrei Pikas <gdb@mail.api.win>
> Cc: Eli Zaretskii <eliz@gnu.org>,
> 	Andrei Pikas <gdb@mail.api.win>
> Date: Sun, 10 Jul 2022 13:10:03 +0300
> 
> 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/1BbgNwpFa0DvKX0K9UAd48dEgtn8aChXP/view
> ---
>  gdb/NEWS            |  4 ++++
>  gdb/cli/cli-style.c | 35 +++++++++++++++++++++++++++++++++++
>  gdb/cli/cli-style.h |  3 +++
>  gdb/doc/gdb.texinfo |  3 +++
>  gdb/tui/tui-io.c    | 38 ++++++++++++++++++++++++++++++++++----
>  gdb/tui/tui-win.c   |  1 +
>  6 files changed, 80 insertions(+), 4 deletions(-)

The documentation parts are OK, thanks.

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

* Re: [PATCH v2 (mentions of reverse mode eliminated)] Add style tui-cursorline command to colorize TUI current line.
  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-15 22:49           ` [PATCH v3] Add style tui-current-line " Andrei Pikas
  1 sibling, 2 replies; 17+ messages in thread
From: Tom Tromey @ 2022-07-15 19:40 UTC (permalink / raw)
  To: Andrei Pikas; +Cc: gdb-patches

>>>>> "Andrei" == Andrei Pikas <gdb@mail.api.win> writes:

Andrei> Adds the ability to customize the colors of the current line of code in TUI.
Andrei> This may be desirable when code highlighting is enabled. Because higlighted
Andrei> keywords in dark blue color are indistinguishable from a black background
Andrei> (which is the default inverse color for a white terminal).
Andrei> Here is a screenshot of old and new behavior
Andrei> https://drive.google.com/file/d/1BbgNwpFa0DvKX0K9UAd48dEgtn8aChXP/view

Thank you for the patch.

Andrei> +set style tui-cursorline foreground COLOR
Andrei> +set style tui-cursorline background COLOR

I think I'd prefer a hyphen in there, since "cursorline" isn't a word.
So, tui-cursor-line.  But why "cursor" and not "current"?  "current
line" seems to be the term used in the gdb manual.

Andrei> @@ -54,6 +54,28 @@ static const char * const cli_colors[] = {
Andrei>    "magenta",
Andrei>    "cyan",
Andrei>    "white",
Andrei> +  "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",

What's this for?

 
Andrei> +static bool
Andrei> +get_custom_cursorline_style (ui_file_style *style)
Andrei> +{

Please add an introductory comment explaining the purpose of the
function.

Andrei> +  ui_file_style cursorline_style = tui_cursorline_style.style();

Space before "(".  There are a couple instances of this here.

Andrei>  	case '\n':
Andrei> +          if (wattr_get (w, &w_attrs, &w_pair, nullptr) == OK)
Andrei> +            /* Apply current style till the end of line. */
Andrei> +            wchgat (w, -1, w_attrs, w_pair, nullptr);

I don't think this is correct, because the source window may not extend
to the end of the line.

Tom

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

* Re: [PATCH v2 (mentions of reverse mode eliminated)] Add style tui-cursorline command to colorize TUI current line.
  2022-07-15 19:40         ` Tom Tromey
@ 2022-07-15 22:06           ` Andrei Pikas
  2022-07-18 14:16             ` Andrew Burgess
  2022-07-15 22:49           ` [PATCH v3] Add style tui-current-line " Andrei Pikas
  1 sibling, 1 reply; 17+ messages in thread
From: Andrei Pikas @ 2022-07-15 22:06 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

 > I think I'd prefer a hyphen in there, since "cursorline" isn't a word.
 > So, tui-cursor-line.  But why "cursor" and not "current"? "current
 > line" seems to be the term used in the gdb manual.

I chose this name to match vim for those who familiar with :set 
cursorline. OK, I'll change it to tui-cursor-line. Or would you prefer 
tui-current-line?



 > Andrei> @@ -54,6 +54,28 @@ static const char * const cli_colors[] = {
 > Andrei>    "magenta",
 > Andrei>    "cyan",
 > Andrei>    "white",
 > Andrei> +  "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", 
"18", "19", "20",
 >
 > What's this for?

This is to support all 256 colors 
https://www.ditig.com/256-colors-cheat-sheet . I want to use the 
lightest shade of gray #255 for the background.


 > Andrei>      case '\n':
 > Andrei> +          if (wattr_get (w, &w_attrs, &w_pair, nullptr) == OK)
 > Andrei> +            /* Apply current style till the end of line. */
 > Andrei> +            wchgat (w, -1, w_attrs, w_pair, nullptr);
 >
 > I don't think this is correct, because the source window may not extend
 > to the end of the line.

I tested for long line. It doesn't seem to be a problem (screenshot 
https://drive.google.com/file/d/1lMgdR9cTNEQJAz05wO7TCgd3SVYOdXyP/view?usp=sharing 
).

I think -1 handles this case: "A character count of -1 or greater than 
the remaining window width means to change attributes all the way to the 
end of the current line." from https://linux.die.net/man/3/wchgat

I can rewrite this line as wchgat (w, std::max (0, getmaxx (w) - getcurx 
(w)), w_attrs, w_pair, nullptr). But I think it's the same.

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

* [PATCH v3] Add style tui-current-line command to colorize TUI current line.
  2022-07-15 19:40         ` Tom Tromey
  2022-07-15 22:06           ` Andrei Pikas
@ 2022-07-15 22:49           ` Andrei Pikas
  2022-07-16  5:35             ` Eli Zaretskii
  2022-07-18 14:30             ` Andrew Burgess
  1 sibling, 2 replies; 17+ messages in thread
From: Andrei Pikas @ 2022-07-15 22:49 UTC (permalink / raw)
  To: tom; +Cc: gdb-patches, Andrei Pikas

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/1BbgNwpFa0DvKX0K9UAd48dEgtn8aChXP/view
---
 gdb/NEWS            |  4 ++++
 gdb/cli/cli-style.c | 36 ++++++++++++++++++++++++++++++++++++
 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, 87 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..64312809385 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -54,6 +54,28 @@ static const char * const cli_colors[] = {
   "magenta",
   "cyan",
   "white",
+  "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
+  "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33",
+  "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
+  "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
+  "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72",
+  "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85",
+  "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98",
+  "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109",
+  "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120",
+  "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131",
+  "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142",
+  "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153",
+  "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164",
+  "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175",
+  "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186",
+  "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197",
+  "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208",
+  "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219",
+  "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230",
+  "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241",
+  "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252",
+  "253", "254", "255",
   nullptr
 };
 
@@ -101,6 +123,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 +473,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..4517cc7124a 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


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

* Re: [PATCH v3] Add style tui-current-line command to colorize TUI current line.
  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
  1 sibling, 0 replies; 17+ messages in thread
From: Eli Zaretskii @ 2022-07-16  5:35 UTC (permalink / raw)
  To: Andrei Pikas; +Cc: tom, gdb, gdb-patches

> From: Andrei Pikas <gdb@mail.api.win>
> Date: Sat, 16 Jul 2022 01:49:49 +0300
> Cc: Andrei Pikas <gdb@mail.api.win>, gdb-patches@sourceware.org
> 
> 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/1BbgNwpFa0DvKX0K9UAd48dEgtn8aChXP/view
> ---
>  gdb/NEWS            |  4 ++++
>  gdb/cli/cli-style.c | 36 ++++++++++++++++++++++++++++++++++++
>  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, 87 insertions(+), 4 deletions(-)

Thanks, the documentation parts are OK.

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

* Re: [PATCH v2 (mentions of reverse mode eliminated)] Add style tui-cursorline command to colorize TUI current line.
  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
  0 siblings, 2 replies; 17+ messages in thread
From: Andrew Burgess @ 2022-07-18 14:16 UTC (permalink / raw)
  To: Andrei Pikas, Tom Tromey; +Cc: gdb-patches

Andrei Pikas <gdb@mail.api.win> writes:

>  > I think I'd prefer a hyphen in there, since "cursorline" isn't a word.
>  > So, tui-cursor-line.  But why "cursor" and not "current"? "current
>  > line" seems to be the term used in the gdb manual.
>
> I chose this name to match vim for those who familiar with :set 
> cursorline. OK, I'll change it to tui-cursor-line. Or would you prefer 
> tui-current-line?
>
>
>
>  > Andrei> @@ -54,6 +54,28 @@ static const char * const cli_colors[] = {
>  > Andrei>    "magenta",
>  > Andrei>    "cyan",
>  > Andrei>    "white",
>  > Andrei> +  "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", 
> "18", "19", "20",
>  >
>  > What's this for?
>
> This is to support all 256 colors 
> https://www.ditig.com/256-colors-cheat-sheet . I want to use the 
> lightest shade of gray #255 for the background.

Thanks.  I've been playing with adding 256 colour support to GDB.

I think this change is big enough that it should be split into a
separate patch.  It certainly deserves its own NEWS entry, and probably
requires a docs update to indicate what all these (seemingly) random
numbers mean.

Thanks,
Andrew



>
>
>  > Andrei>      case '\n':
>  > Andrei> +          if (wattr_get (w, &w_attrs, &w_pair, nullptr) == OK)
>  > Andrei> +            /* Apply current style till the end of line. */
>  > Andrei> +            wchgat (w, -1, w_attrs, w_pair, nullptr);
>  >
>  > I don't think this is correct, because the source window may not extend
>  > to the end of the line.
>
> I tested for long line. It doesn't seem to be a problem (screenshot 
> https://drive.google.com/file/d/1lMgdR9cTNEQJAz05wO7TCgd3SVYOdXyP/view?usp=sharing 
> ).
>
> I think -1 handles this case: "A character count of -1 or greater than 
> the remaining window width means to change attributes all the way to the 
> end of the current line." from https://linux.die.net/man/3/wchgat
>
> I can rewrite this line as wchgat (w, std::max (0, getmaxx (w) - getcurx 
> (w)), w_attrs, w_pair, nullptr). But I think it's the same.


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

* Re: [PATCH v3] Add style tui-current-line command to colorize TUI current line.
  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               ` [PATCH v4 (fix formatting and revert cli_colors to original state)] " Andrei Pikas
  1 sibling, 1 reply; 17+ messages in thread
From: Andrew Burgess @ 2022-07-18 14:30 UTC (permalink / raw)
  To: Andrei Pikas, tom; +Cc: Andrei Pikas, gdb-patches

Andrei Pikas <gdb@mail.api.win> writes:

> 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/1BbgNwpFa0DvKX0K9UAd48dEgtn8aChXP/view
> ---
>  gdb/NEWS            |  4 ++++
>  gdb/cli/cli-style.c | 36 ++++++++++++++++++++++++++++++++++++
>  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, 87 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..64312809385 100644
> --- a/gdb/cli/cli-style.c
> +++ b/gdb/cli/cli-style.c
> @@ -54,6 +54,28 @@ static const char * const cli_colors[] = {
>    "magenta",
>    "cyan",
>    "white",
> +  "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
> +  "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33",
> +  "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
> +  "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
> +  "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72",
> +  "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85",
> +  "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98",
> +  "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109",
> +  "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120",
> +  "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131",
> +  "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142",
> +  "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153",
> +  "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164",
> +  "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175",
> +  "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186",
> +  "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197",
> +  "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208",
> +  "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219",
> +  "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230",
> +  "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241",
> +  "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252",
> +  "253", "254", "255",

As I said in another mail, I think this change needs spinning out into
its own patch.

>    nullptr
>  };
>  
> @@ -101,6 +123,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);

Continuation lines like this should be indented initially with TABS, and
the alignment should be like:

  cli_style_option tui_current_line_style ("tui-current-line",
                                           ui_file_style::NONE);

See tui_active_border_style for an example.

Thanks,
Andrew

> +
> +/* See cli-style.h.  */
> +
>  cli_style_option metadata_style ("metadata", ui_file_style::DIM);
>  
>  /* See cli-style.h.  */
> @@ -446,6 +473,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..4517cc7124a 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


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

* Re: [PATCH v2 (mentions of reverse mode eliminated)] Add style tui-cursorline command to colorize TUI current line.
  2022-07-18 14:16             ` Andrew Burgess
@ 2022-07-18 15:32               ` Andrei Pikas
  2022-07-18 18:12               ` Tom Tromey
  1 sibling, 0 replies; 17+ messages in thread
From: Andrei Pikas @ 2022-07-18 15:32 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

> > This is to support all 256 colors
> > https://www.ditig.com/256-colors-cheat-sheet . I want to use the
> > lightest shade of gray #255 for the background.
>
> Thanks.  I've been playing with adding 256 colour support to GDB.
>
> I think this change is big enough that it should be split into a
> separate patch.
Do you think it's OK to set colors as enum without corresponding
numbers for colors 0-7?
Or maybe it would be better to add something like case var_color: into
do_set_command to support all possible colors which
ui_file_style::color supports?
Or maybe just to store value as simple var_string, but to extend
struct cmd_list_element with custom validation function, to validate
color string at the time of setting, rather then on first use?

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

* Re: [PATCH v2 (mentions of reverse mode eliminated)] Add style tui-cursorline command to colorize TUI current line.
  2022-07-18 14:16             ` Andrew Burgess
  2022-07-18 15:32               ` Andrei Pikas
@ 2022-07-18 18:12               ` Tom Tromey
  1 sibling, 0 replies; 17+ messages in thread
From: Tom Tromey @ 2022-07-18 18:12 UTC (permalink / raw)
  To: Andrew Burgess via Gdb-patches; +Cc: Andrei Pikas, Tom Tromey, Andrew Burgess

>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:

Andrew> Thanks.  I've been playing with adding 256 colour support to GDB.

I'm supportive of this, but I'd also like to ensure it's done in a way
that doesn't preclude 24-bit "truecolor" support.  Many common terminal
emulators support that nowadays.

Tom

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

* [PATCH v4 (fix formatting and revert cli_colors to original state)] Add style tui-current-line command to colorize TUI current line.
  2022-07-18 14:30             ` Andrew Burgess
@ 2022-07-18 19:11               ` Andrei Pikas
  2022-07-18 19:14                 ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Andrei Pikas @ 2022-07-18 19:11 UTC (permalink / raw)
  To: gdb-patches; +Cc: aburgess, Andrei Pikas

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


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

* Re: [PATCH v4 (fix formatting and revert cli_colors to original state)] Add style tui-current-line command to colorize TUI current line.
  2022-07-18 19:11               ` [PATCH v4 (fix formatting and revert cli_colors to original state)] " Andrei Pikas
@ 2022-07-18 19:14                 ` Eli Zaretskii
  2022-07-18 19:16                   ` Andrei Pikas
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2022-07-18 19:14 UTC (permalink / raw)
  To: Andrei Pikas; +Cc: gdb-patches, gdb, aburgess

> From: Andrei Pikas <gdb@mail.api.win>
> Date: Mon, 18 Jul 2022 22:11:18 +0300
> Cc: Andrei Pikas <gdb@mail.api.win>, aburgess@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(-)

The documentation parts are unchanged since I approved them, right?

Thanks.

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

* Re: [PATCH v4 (fix formatting and revert cli_colors to original state)] Add style tui-current-line command to colorize TUI current line.
  2022-07-18 19:14                 ` Eli Zaretskii
@ 2022-07-18 19:16                   ` Andrei Pikas
  0 siblings, 0 replies; 17+ messages in thread
From: Andrei Pikas @ 2022-07-18 19:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

 > The documentation parts are unchanged since I approved them, right?

Yes, it's right.

On 18/07/2022 22:14, Eli Zaretskii wrote:
>> From: Andrei Pikas <gdb@mail.api.win>
>> Date: Mon, 18 Jul 2022 22:11:18 +0300
>> Cc: Andrei Pikas <gdb@mail.api.win>, aburgess@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(-)
> The documentation parts are unchanged since I approved them, right?
>
> Thanks.

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

end of thread, other threads:[~2022-07-18 19:16 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-09 19:05 [PATCH] Add style tui-reverse command to colorize TUI current line 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               ` [PATCH v4 (fix formatting and revert cli_colors to original state)] " Andrei Pikas
2022-07-18 19:14                 ` Eli Zaretskii
2022-07-18 19:16                   ` Andrei Pikas

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