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 3/3] [gdb/tui] Add tui border-kind active-ascii
Date: Mon,  8 May 2023 16:10:36 +0200	[thread overview]
Message-ID: <20230508141036.22723-4-tdevries@suse.de> (raw)
In-Reply-To: <20230508141036.22723-1-tdevries@suse.de>

I noticed that after configuring TUI to just use plain ascii borders:
...
(gdb) show tui
tui active-border-mode:  The attribute mode to use for the active TUI window \
  border is "normal".
tui border-kind:  The kind of border for TUI windows is "ascii".
tui border-mode:  The attribute mode to use for the TUI window borders is \
  "normal".
...
there was no longer something to identify whether a window has focus.

Add a new border-kind active-ascii, that's like border-kind ascii for inactive
windows but uses '+' as hline and vline (instead of '-' and '|') for an active
window.

In other words, this border for an inactive window:
...
+-+
| |
+-+
...
and this border for an active window:
...
+++
+ +
+++
...

Tested on x86_64-linux.
---
 gdb/doc/gdb.texinfo                 |  4 ++
 gdb/testsuite/gdb.tui/tui-focus.exp |  7 +++-
 gdb/testsuite/lib/tuiterm.exp       | 49 ++++++++++++++-----------
 gdb/tui/tui-win.c                   | 57 ++++++++++++++++++++++++++---
 gdb/tui/tui-win.h                   |  6 +++
 gdb/tui/tui-wingeneral.c            | 17 ++++++---
 6 files changed, 107 insertions(+), 33 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 8c4177c1901..f5fda5f57a8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30267,6 +30267,10 @@ Use a space character to draw the border.
 @item ascii
 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
 
+@item active-ascii
+Use @sc{ascii} character @samp{+} to draw the border of an active
+window, otherwise as border-kind @code{ascii}.
+
 @item acs
 Use the Alternate Character Set to draw the border.  The border is
 drawn using character line graphics if the terminal supports them.
diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp
index 72f80523af3..42629821888 100644
--- a/gdb/testsuite/gdb.tui/tui-focus.exp
+++ b/gdb/testsuite/gdb.tui/tui-focus.exp
@@ -41,6 +41,10 @@ foreach spec {{src true} {cmd true} {status true} {regs false} \
 	    unsupported "TUI not supported"
 	    return
 	}
+	gdb_test_no_output "set tui border-kind active-ascii"
+
+	# Initial value, will be effective if "focus $window" fails.
+	set src_focus 1
 
 	Term::command_no_prompt_prefix "focus $window"
 
@@ -53,6 +57,7 @@ foreach spec {{src true} {cmd true} {status true} {regs false} \
 	    } else {
 		Term::check_region_contents "check focus message" 0 16 80 1 \
 		    "^Focus set to $window window\\.\\s*"
+		set src_focus [string equal $window "src"]
 	    }
 	} else {
 	    if {$window == "unknown"} {
@@ -64,7 +69,7 @@ foreach spec {{src true} {cmd true} {status true} {regs false} \
 	    }
 	}
 
-	Term::check_box "check src box" 0 0 80 15
+	Term::check_box "check src box" 0 0 80 15 $src_focus
 
 	# At one point the following 'focus prev' command would trigger a
 	# crash in GDB, GDB was allowing users to set focus to the 'status'
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 5e4235da942..ef89d0a8a2c 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -928,30 +928,33 @@ namespace eval Term {
 
     # Helper function for check_box.  Returns empty string if the box
     # is found, description of why not otherwise.
-    proc _check_box {x y width height} {
+    proc _check_box {x y width height hline vline corner} {
 	set x2 [expr {$x + $width - 1}]
 	set y2 [expr {$y + $height - 1}]
 
-	verbose -log "_check_box x=$x, y=$y, x2=$x2, y2=$y2, width=$width, height=$height"
+	verbose -log [join [list _check_box x=$x y=$y x2=$x2 y2=$y2 \
+				width=$width height=$height \
+				hline=$hline vline=$vline \
+				corner=$corner] ", "]
 
 	set c [get_char $x $y]
-	if {$c != "+"} {
-	    return "ul corner is $c, not +"
+	if {$c != $corner} {
+	    return "ul corner is $c, not $corner"
 	}
 
 	set c [get_char $x $y2]
-	if {$c != "+"} {
-	    return "ll corner is $c, not +"
+	if {$c != $corner} {
+	    return "ll corner is $c, not $corner"
 	}
 
 	set c [get_char $x2 $y]
-	if {$c != "+"} {
-	    return "ur corner is $c, not +"
+	if {$c != $corner} {
+	    return "ur corner is $c, not $corner"
 	}
 
 	set c [get_char $x2 $y2]
 	if {$c != "+"} {
-	    return "lr corner is $c, not +"
+	    return "lr corner is $c, not $corner"
 	}
 
 	# Note we do not check the full horizonal borders of the box.
@@ -960,25 +963,25 @@ namespace eval Term {
 	# title should appear as '+-VERY LONG TITLE-+', so we can
 	# check for the '+-' on the left, and '-+' on the right.
 	set c [get_char [expr {$x + 1}] $y]
-	if {$c != "-"} {
-	    return "ul title padding is $c, not -"
+	if {$c != $hline} {
+	    return "ul title padding is $c, not $hline"
 	}
 
 	set c [get_char [expr {$x2 - 1}] $y]
-	if {$c != "-"} {
-	    return "ul title padding is $c, not -"
+	if {$c != $hline} {
+	    return "ul title padding is $c, not $hline"
 	}
 
 	# Now check the vertical borders.
 	for {set i [expr {$y + 1}]} {$i < $y2 - 1} {incr i} {
 	    set c [get_char $x $i]
-	    if {$c != "|"} {
-		return "left side $i is $c, not |"
+	    if {$c != $vline} {
+		return "left side $i is $c, not $vline"
 	    }
 
 	    set c [get_char $x2 $i]
-	    if {$c != "|"} {
-		return "right side $i is $c, not |"
+	    if {$c != $vline} {
+		return "right side $i is $c, not $vline"
 	    }
 	}
 
@@ -986,9 +989,13 @@ namespace eval Term {
     }
 
     # Check for a box at the given coordinates.
-    proc check_box {test_name x y width height} {
+    proc check_box {test_name x y width height {active 0}} {
 	dump_box $x $y $width $height
-	set why [_check_box $x $y $width $height]
+	if { $active } {
+	    set why [_check_box $x $y $width $height "+" "+" "+"]
+	} else {
+	    set why [_check_box $x $y $width $height "-" "|" "+"]
+	}
 	if {$why == ""} {
 	    pass $test_name
 	} else {
@@ -996,7 +1003,7 @@ namespace eval Term {
 	}
     }
 
-    # Check whether the text contents of the terminal match the
+# Check whether the text contents of the terminal match the
     # regular expression.  Note that text styling is not considered.
     proc check_contents {test_name regexp} {
 	dump_screen
@@ -1058,7 +1065,7 @@ namespace eval Term {
 	variable _chars
 
 	dump_box $x $y $width $height
-	set why [_check_box $x $y $width $height]
+	set why [_check_box $x $y $width $height "-" "|" "+"]
 	if {$why != ""} {
 	    fail "$test_name (box check: $why)"
 	    return
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index fedcac4b560..ef8cb120657 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -93,6 +93,7 @@ static void parse_scrolling_args (const char *,
 static const char *const tui_border_kind_enums[] = {
   "space",
   "ascii",
+  "active-ascii",
   "acs",
   NULL
 };
@@ -137,6 +138,7 @@ static struct tui_translate tui_border_mode_translate[] = {
 static struct tui_translate tui_border_kind_translate_vline[] = {
   { "space",    ' ' },
   { "ascii",    '|' },
+  { "active-ascii", '+' },
   { "acs",      -1 },
   { 0, 0 },
   { "ascii",    '|' }
@@ -145,6 +147,7 @@ static struct tui_translate tui_border_kind_translate_vline[] = {
 static struct tui_translate tui_border_kind_translate_hline[] = {
   { "space",    ' ' },
   { "ascii",    '-' },
+  { "active-ascii", '+' },
   { "acs",      -1 },
   { 0, 0 },
   { "ascii",    '-' }
@@ -153,6 +156,7 @@ static struct tui_translate tui_border_kind_translate_hline[] = {
 static struct tui_translate tui_border_kind_translate_ulcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
+  { "active-ascii", '+' },
   { "acs",      -1 },
   { 0, 0 },
   { "ascii",    '+' }
@@ -161,6 +165,7 @@ static struct tui_translate tui_border_kind_translate_ulcorner[] = {
 static struct tui_translate tui_border_kind_translate_urcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
+  { "active-ascii", '+' },
   { "acs",      -1 },
   { 0, 0 },
   { "ascii",    '+' }
@@ -169,6 +174,7 @@ static struct tui_translate tui_border_kind_translate_urcorner[] = {
 static struct tui_translate tui_border_kind_translate_llcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
+  { "active-ascii", '+' },
   { "acs",      -1 },
   { 0, 0 },
   { "ascii",    '+' }
@@ -177,6 +183,7 @@ static struct tui_translate tui_border_kind_translate_llcorner[] = {
 static struct tui_translate tui_border_kind_translate_lrcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
+  { "active-ascii", '+' },
   { "acs",      -1 },
   { 0, 0 },
   { "ascii",    '+' }
@@ -253,6 +260,12 @@ chtype tui_border_ulcorner;
 chtype tui_border_urcorner;
 chtype tui_border_llcorner;
 chtype tui_border_lrcorner;
+chtype tui_active_border_vline;
+chtype tui_active_border_hline;
+chtype tui_active_border_ulcorner;
+chtype tui_active_border_urcorner;
+chtype tui_active_border_llcorner;
+chtype tui_active_border_lrcorner;
 
 int tui_border_attrs;
 int tui_active_border_attrs;
@@ -323,30 +336,61 @@ tui_update_variables ()
   set_border_attrs (&tui_active_border_attrs, tui_active_border_mode,
 		    tui_border_mode_translate, &need_redraw);
 
+  /* For inactive borders, active-ascii is the same as ascii.  */
+  const char *tui_inactive_border_kind
+    = ((strcmp (tui_border_kind, "active-ascii") == 0)
+       ? "ascii"
+       : tui_border_kind);
+  const char *tui_active_border_kind = tui_border_kind;
+
   /* The ACS characters are determined at run time by curses terminal
      management.  */
 
-  set_border_kind_item (&tui_border_lrcorner, tui_border_kind,
+  set_border_kind_item (&tui_border_lrcorner, tui_inactive_border_kind,
+			tui_border_kind_translate_lrcorner, ACS_LRCORNER,
+			&need_redraw);
+
+  set_border_kind_item (&tui_border_llcorner, tui_inactive_border_kind,
+			tui_border_kind_translate_llcorner, ACS_LLCORNER,
+			&need_redraw);
+
+  set_border_kind_item (&tui_border_ulcorner, tui_inactive_border_kind,
+			tui_border_kind_translate_ulcorner, ACS_ULCORNER,
+			&need_redraw);
+
+  set_border_kind_item (&tui_border_urcorner, tui_inactive_border_kind,
+			tui_border_kind_translate_urcorner, ACS_URCORNER,
+			&need_redraw);
+
+  set_border_kind_item (&tui_border_hline, tui_inactive_border_kind,
+			tui_border_kind_translate_hline, ACS_HLINE,
+			&need_redraw);
+
+  set_border_kind_item (&tui_border_vline, tui_inactive_border_kind,
+			tui_border_kind_translate_vline, ACS_VLINE,
+			&need_redraw);
+
+  set_border_kind_item (&tui_active_border_lrcorner, tui_active_border_kind,
 			tui_border_kind_translate_lrcorner, ACS_LRCORNER,
 			&need_redraw);
 
-  set_border_kind_item (&tui_border_llcorner, tui_border_kind,
+  set_border_kind_item (&tui_active_border_llcorner, tui_active_border_kind,
 			tui_border_kind_translate_llcorner, ACS_LLCORNER,
 			&need_redraw);
 
-  set_border_kind_item (&tui_border_ulcorner, tui_border_kind,
+  set_border_kind_item (&tui_active_border_ulcorner, tui_active_border_kind,
 			tui_border_kind_translate_ulcorner, ACS_ULCORNER,
 			&need_redraw);
 
-  set_border_kind_item (&tui_border_urcorner, tui_border_kind,
+  set_border_kind_item (&tui_active_border_urcorner, tui_active_border_kind,
 			tui_border_kind_translate_urcorner, ACS_URCORNER,
 			&need_redraw);
 
-  set_border_kind_item (&tui_border_hline, tui_border_kind,
+  set_border_kind_item (&tui_active_border_hline, tui_active_border_kind,
 			tui_border_kind_translate_hline, ACS_HLINE,
 			&need_redraw);
 
-  set_border_kind_item (&tui_border_vline, tui_border_kind,
+  set_border_kind_item (&tui_active_border_vline, tui_active_border_kind,
 			tui_border_kind_translate_vline, ACS_VLINE,
 			&need_redraw);
 
@@ -1244,6 +1288,7 @@ Show the kind of border for TUI windows."), _("\
 This variable controls the border of TUI windows:\n\
    space           use a white space\n\
    ascii           use ascii characters + - | for the border\n\
+   active-ascii    use ascii character + for the active border, otherwise as ascii\n\
    acs             use the Alternate Character Set"),
 			tui_set_var_cmd,
 			show_tui_border_kind,
diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h
index 3d35f1dfb7f..0c02cc3e2e9 100644
--- a/gdb/tui/tui-win.h
+++ b/gdb/tui/tui-win.h
@@ -35,6 +35,12 @@ extern chtype tui_border_lrcorner;
 extern chtype tui_border_llcorner;
 extern chtype tui_border_vline;
 extern chtype tui_border_hline;
+extern chtype tui_active_border_vline;
+extern chtype tui_active_border_hline;
+extern chtype tui_active_border_ulcorner;
+extern chtype tui_active_border_urcorner;
+extern chtype tui_active_border_llcorner;
+extern chtype tui_active_border_lrcorner;
 extern int tui_border_attrs;
 extern int tui_active_border_attrs;
 
diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c
index 82a023d09fe..ac07195c81f 100644
--- a/gdb/tui/tui-wingeneral.c
+++ b/gdb/tui/tui-wingeneral.c
@@ -99,12 +99,19 @@ box_win (struct tui_win_info *win_info,
 			   : tui_border_style.style ()));
   wattron (win, attrs);
 #ifdef HAVE_WBORDER
-  wborder (win, tui_border_vline, tui_border_vline,
-	   tui_border_hline, tui_border_hline,
-	   tui_border_ulcorner, tui_border_urcorner,
-	   tui_border_llcorner, tui_border_lrcorner);
+  wborder (win,
+	   highlight_flag ? tui_active_border_vline : tui_border_vline,
+	   highlight_flag ? tui_active_border_vline : tui_border_vline,
+	   highlight_flag ? tui_active_border_hline : tui_border_hline,
+	   highlight_flag ? tui_active_border_hline : tui_border_hline,
+	   highlight_flag ? tui_active_border_ulcorner : tui_border_ulcorner,
+	   highlight_flag ? tui_active_border_urcorner : tui_border_urcorner,
+	   highlight_flag ? tui_active_border_llcorner : tui_border_llcorner,
+	   highlight_flag ? tui_active_border_lrcorner : tui_border_lrcorner);
 #else
-  box (win, tui_border_vline, tui_border_hline);
+  box (win,
+       highlight_flag ? tui_active_border_vline : tui_border_vline,
+       highlight_flag ? tui_active_border_hline : tui_border_hline);
 #endif
   if (!win_info->title.empty ())
     {
-- 
2.35.3


  parent reply	other threads:[~2023-05-08 14:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 14:10 [PATCH 0/3] " Tom de Vries
2023-05-08 14:10 ` [PATCH 1/3] [gdb/tui] Make tui_update_variables more readable Tom de Vries
2023-12-15 19:48   ` Tom Tromey
2023-05-08 14:10 ` [PATCH 2/3] [gdb/tui] Fix buglet in set_border_kind_item Tom de Vries
2023-05-22 14:47   ` [pushed] [gdb/tui] Fix buglet in tui_update_variables Tom de Vries
2023-05-08 14:10 ` Tom de Vries [this message]
2023-12-15 19:50   ` [PATCH 3/3] [gdb/tui] Add tui border-kind active-ascii Tom Tromey
2023-12-15 20:04     ` 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=20230508141036.22723-4-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).