public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/3] [gdb/tui] Add set tui status-window-mode <mode>
Date: Tue, 16 May 2023 10:43:50 +0200	[thread overview]
Message-ID: <20230516084352.27225-2-tdevries@suse.de> (raw)
In-Reply-To: <20230516084352.27225-1-tdevries@suse.de>

Currently, the status window attributes are hardcoded to standout.

Add a new command "set tui status-window-mode <mode>" that controls the
attributes for the status window, using the same <mode> options as used
for "set tui border-mode" and "set tui active-border-mode".

The default is standout, so there's no change in behaviour.

Tested on x86_64-linux.
---
 gdb/doc/gdb.texinfo             |  6 +++
 gdb/testsuite/gdb.tui/basic.exp | 13 +++++
 gdb/testsuite/lib/tuiterm.exp   | 84 +++++++++++++++++++++++++--------
 gdb/tui/tui-stack.c             | 10 ++--
 gdb/tui/tui-win.c               | 56 ++++++++++++++++++++++
 gdb/tui/tui-win.h               |  3 ++
 6 files changed, 146 insertions(+), 26 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 531147f6e6b..77bc4323912 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30302,6 +30302,12 @@ Use extra bright or bold mode.
 Use extra bright or bold and standout mode.
 @end table
 
+@item set tui status-window-mode @var{mode}
+@kindex set tui status-window-mode
+Select the display attributes for the contents of the status window.
+The @var{mode} is as for @code{set tui border-mode} and
+@code{set tui border-active-mode}.  The default is standout mode.
+
 @item set tui tab-width @var{nchars}
 @kindex set tui tab-width
 @kindex tabset
diff --git a/gdb/testsuite/gdb.tui/basic.exp b/gdb/testsuite/gdb.tui/basic.exp
index ec1e9945e8f..4cff8ea41d7 100644
--- a/gdb/testsuite/gdb.tui/basic.exp
+++ b/gdb/testsuite/gdb.tui/basic.exp
@@ -106,3 +106,16 @@ Term::check_contents "split layout contents" \
 
 Term::check_box "source box in split layout" 0 0 80 8
 Term::check_box "asm box in split layout" 0 7 80 8
+
+set re_noattr "\[^<\]"
+
+set status_window_line 15
+
+set status [Term::get_line_with_attrs $status_window_line]
+gdb_assert { [regexp "^<reverse:1>$re_noattr*<reverse:0>$" $status] == 1} \
+    "status window: reverse"
+
+Term::command "set tui status-window-mode normal"
+
+set status [Term::get_line_with_attrs $status_window_line]
+gdb_assert { [regexp "^$re_noattr*$" $status] == 1} "status window: normal"
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 5e4235da942..8305e83e982 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -547,6 +547,18 @@ namespace eval Term {
 	}
     }
 
+    # Reset the attributes in attributes array UPVAR_NAME to the default values.
+    proc reset_attrs { upvar_name } {
+	upvar $upvar_name var
+	array set var {
+	    intensity normal
+	    fg default
+	    bg default
+	    underline 0
+	    reverse 0
+	}
+    }
+
     # Select Graphic Rendition.
     #
     # https://vt100.net/docs/vt510-rm/SGR.html
@@ -557,11 +569,7 @@ namespace eval Term {
 	  foreach item $args {
 	      switch -exact -- $item {
 		  "" - 0 {
-		      set _attrs(intensity) normal
-		      set _attrs(fg) default
-		      set _attrs(bg) default
-		      set _attrs(underline) 0
-		      set _attrs(reverse) 0
+		      reset_attrs _attrs
 		  }
 		  1 {
 		      set _attrs(intensity) bold
@@ -666,13 +674,7 @@ namespace eval Term {
 	set _cur_col 0
 	set _cur_row 0
 	set _resize_count 0
-	array set _attrs {
-	    intensity normal
-	    fg default
-	    bg default
-	    underline 0
-	    reverse 0
-	}
+	reset_attrs _attrs
 
 	_clear_lines 0 $_rows
     }
@@ -873,10 +875,25 @@ namespace eval Term {
 	wait_for "^$str"
     }
 
-    # Return the text of screen line N, without attributes.  Lines are
-    # 0-based.  If C is given, stop before column C.  Columns are also
-    # zero-based.
-    proc get_line {n {c ""}} {
+    # Apply the attribute list in ATTRS to attributes array UPVAR_NAME.
+    # Return a string annotating the changed attributes.
+    proc apply_attrs { upvar_name attrs } {
+	set res ""
+	upvar $upvar_name var
+	foreach { attr val } $attrs {
+	    if { $var($attr) != $val } {
+		append res "<$attr:$val>"
+		set var($attr) $val
+	    }
+	}
+
+	return $res
+    }
+
+    # Return the text of screen line N.  Lines are 0-based.  If C is given,
+    # stop before column C.  Columns are also zero-based.  If ATTRS, annotate
+    # with attributes.
+    proc get_line_1 {n c attrs} {
 	variable _rows
 	# This can happen during resizing, if the cursor seems to
 	# temporarily be off-screen.
@@ -889,13 +906,37 @@ namespace eval Term {
 	variable _chars
 	set c [_default $c $_cols]
 	set x 0
+	if { $attrs } {
+	    reset_attrs line_attrs
+	}
 	while {$x < $c} {
+	    if { $attrs } {
+		set char_attrs [lindex $_chars($x,$n) 1]
+		append result [apply_attrs line_attrs $char_attrs]
+	    }
 	    append result [lindex $_chars($x,$n) 0]
 	    incr x
 	}
+	if { $attrs } {
+	    reset_attrs zero_attrs
+	    set char_attrs [array get zero_attrs]
+	    append result [apply_attrs line_attrs $char_attrs]
+	}
 	return $result
     }
 
+    # Return the text of screen line N, without attributes.  Lines are
+    # 0-based.  If C is given, stop before column C.  Columns are also
+    # zero-based.
+    proc get_line {n {c ""} } {
+	return [get_line_1 $n $c 0]
+    }
+
+    # As get_line, but annotate with attributes.
+    proc get_line_with_attrs {n {c ""}} {
+	return [get_line_1 $n $c 1]
+    }
+
     # Get just the character at (X, Y).
     proc get_char {x y} {
 	variable _chars
@@ -1069,8 +1110,8 @@ namespace eval Term {
     }
 
     # A debugging function to dump the current screen, with line
-    # numbers.
-    proc dump_screen {} {
+    # numbers.  If ATTRS, annotate with attributes.
+    proc dump_screen { {attrs 0} } {
 	variable _rows
 	variable _cols
 	variable _cur_row
@@ -1080,10 +1121,15 @@ namespace eval Term {
 
 	for {set y 0} {$y < $_rows} {incr y} {
 	    set fmt [format %5d $y]
-	    verbose -log "$fmt [get_line $y]"
+	    verbose -log "$fmt [get_line_1 $y "" $attrs]"
 	}
     }
 
+    # As dump_screen, but with attributes annotation.
+    proc dump_screen_with_attrs {} {
+	return [dump_screen 1]
+    }
+
     # A debugging function to dump a box from the current screen, with line
     # numbers.
     proc dump_box { x y width height } {
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index 76b8f066abb..153a285f37c 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -37,6 +37,7 @@
 #include "tui/tui-winsource.h"
 #include "tui/tui-file.h"
 #include "tui/tui-location.h"
+#include "tui/tui-win.h"
 
 #include "gdb_curses.h"
 
@@ -234,15 +235,10 @@ tui_locator_window::rerender ()
   std::string string = make_status_line ();
   scrollok (handle.get (), FALSE);
   wmove (handle.get (), 0, 0);
-  /* We ignore the return value from wstandout and wstandend, casting them
-     to void in order to avoid a compiler warning.  The warning itself was
-     introduced by a patch to ncurses 5.7 dated 2009-08-29, changing these
-     macro to expand to code that causes the compiler to generate an
-     unused-value warning.  */
-  (void) wstandout (handle.get ());
+  wattron (handle.get (), tui_status_window_attrs);
   waddstr (handle.get (), string.c_str ());
   wclrtoeol (handle.get ());
-  (void) wstandend (handle.get ());
+  wattroff (handle.get (), tui_status_window_attrs);
   refresh_window ();
   wmove (handle.get (), 0, 0);
 }
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 6710b3e17e5..7926e2d7a18 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -346,6 +346,42 @@ tui_set_var_cmd (const char *null_args,
     tui_rehighlight_all ();
 }
 
+/* Value of "tui status-window-mode".  */
+
+static const char *tui_status_window_mode = "standout";
+
+/* See tui-win.h.  */
+
+int tui_status_window_attrs;
+
+/* Show value of "tui status-window-mode".  */
+
+static void
+show_tui_status_window_mode (struct ui_file *file,
+			     int from_tty,
+			     struct cmd_list_element *c,
+			     const char *value)
+{
+  gdb_printf (file, _("\
+The attribute mode to use for the TUI status window is \"%s\".\n"),
+	      value);
+}
+
+/* Set value of "tui status-window-mode".  */
+
+static void
+set_tui_status_window_mode (const char *null_args,
+			    int from_tty, struct cmd_list_element *c)
+{
+  struct tui_translate *entry
+    = translate (tui_status_window_mode, tui_border_mode_translate);
+  if (tui_status_window_attrs == entry->value)
+    return;
+
+  tui_status_window_attrs = entry->value;
+  if (tui_active)
+    tui_show_locator_content ();
+}
 \f
 
 /* True if TUI resizes should print a message.  This is used by the
@@ -1251,6 +1287,22 @@ This variable controls the attributes to use for the active window border:\n\
 			show_tui_active_border_mode,
 			&tui_setlist, &tui_showlist);
 
+  add_setshow_enum_cmd ("status-window-mode", no_class, tui_border_mode_enums,
+			&tui_status_window_mode, _("\
+Set the attribute mode to use for the TUI status window."), _("\
+Show the attribute mode to use for the TUI status window."), _("\
+This variable controls the attributes to use for the status window:\n\
+   normal          normal display\n\
+   standout        use highlight mode of terminal\n\
+   reverse         use reverse video mode\n\
+   half            use half bright\n\
+   half-standout   use half bright and standout mode\n\
+   bold            use extra bright or bold\n\
+   bold-standout   use extra bright or bold with standout mode"),
+			set_tui_status_window_mode,
+			show_tui_status_window_mode,
+			&tui_setlist, &tui_showlist);
+
   add_setshow_zuinteger_cmd ("tab-width", no_class,
 			     &internal_tab_width, _("\
 Set the tab width, in characters, for the TUI."), _("\
@@ -1305,4 +1357,8 @@ When enabled, the left margin will use '_' and '0' instead of spaces."),
 
   tui_border_style.changed.attach (tui_rehighlight_all, "tui-win");
   tui_active_border_style.changed.attach (tui_rehighlight_all, "tui-win");
+
+  /* Assign default value.  */
+  tui_status_window_attrs
+    = translate (tui_status_window_mode, tui_border_mode_translate)->value;
 }
diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h
index 3d35f1dfb7f..5ace83a742a 100644
--- a/gdb/tui/tui-win.h
+++ b/gdb/tui/tui-win.h
@@ -38,6 +38,9 @@ extern chtype tui_border_hline;
 extern int tui_border_attrs;
 extern int tui_active_border_attrs;
 
+/* Attributes for the contents of the status window.  */
+extern int tui_status_window_attrs;
+
 extern bool tui_update_variables ();
 
 extern void tui_initialize_win (void);
-- 
2.35.3


  reply	other threads:[~2023-05-16  8:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16  8:43 [PATCH 0/3] [gdb/tui] Allow highlighting in windows contents to be switched off Tom de Vries
2023-05-16  8:43 ` Tom de Vries [this message]
2023-05-16 15:01   ` [PATCH 1/3] [gdb/tui] Add set tui status-window-mode <mode> Eli Zaretskii
2023-05-19 19:11   ` Tom Tromey
2023-05-22 12:15     ` Tom de Vries
2023-05-16  8:43 ` [PATCH 2/3] [gdb/tui] Use ">" marker in register window Tom de Vries
2023-05-16  8:43 ` [PATCH 3/3] [gdb/tui] Add set tui contents-highlight on/off Tom de Vries
2023-05-16 15:02   ` Eli Zaretskii

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=20230516084352.27225-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).