public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed 3/3] [gdb/testsuite] Add test-case gdb.tui/color-prompt.exp
Date: Fri, 26 May 2023 15:03:00 +0200	[thread overview]
Message-ID: <20230526130300.20974-3-tdevries@suse.de> (raw)
In-Reply-To: <20230526130300.20974-1-tdevries@suse.de>

Add a test-case that sets a prompt with color in TUI.

The line containing the prompt is shown by get_line_with_attrs as follows:
...
<fg:31>(gdb) <fg:default>
...

The 31 means red, but only for foreground colors, for background colors 41
means red.

Make this more readable by using color names for both foreground and
background, such that we have instead:
....
<fg:red>(gdb) <fg:default>
...

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.tui/color-prompt.exp | 32 +++++++++++++++++++++++
 gdb/testsuite/gdb.tui/tuiterm.exp      | 24 +++++++++++++++++-
 gdb/testsuite/lib/tuiterm.exp          | 35 ++++++++++++++++++++++++--
 3 files changed, 88 insertions(+), 3 deletions(-)
 create mode 100644 gdb/testsuite/gdb.tui/color-prompt.exp

diff --git a/gdb/testsuite/gdb.tui/color-prompt.exp b/gdb/testsuite/gdb.tui/color-prompt.exp
new file mode 100644
index 00000000000..8482e1b7695
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/color-prompt.exp
@@ -0,0 +1,32 @@
+# Copyright 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check using a prompt with color in TUI.
+
+tuiterm_env
+
+Term::clean_restart 24 80
+
+# Set colored prompt.
+if {![Term::enter_tui]} {
+    unsupported "TUI not supported"
+    return
+}
+
+Term::command "set prompt \\033\[31m(gdb) \\033\[0m"
+
+set line [Term::get_line_with_attrs $Term::_cur_row]
+gdb_assert { [regexp "^<fg:red>$gdb_prompt <fg:default> *$" $line] } \
+    "prompt with color"
diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp
index bccb7ef445a..c1751418130 100644
--- a/gdb/testsuite/gdb.tui/tuiterm.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm.exp
@@ -699,8 +699,30 @@ proc test_attrs {} {
 	    5 1
 	    25 0
 	}
+	fg {
+	    30 black
+	    31 red
+	    32 green
+	    33 yellow
+	    34 blue
+	    35 magenta
+	    36 cyan
+	    37 white
+	    39 default
+	}
+	bg {
+	    40 black
+	    41 red
+	    42 green
+	    43 yellow
+	    44 blue
+	    45 magenta
+	    46 cyan
+	    47 white
+	    49 default
+	}
     } {
-	setup_terminal 8 1
+	setup_terminal 12 1
 	set re ""
 	foreach { arg val } $vals {
 	    Term::_insert "a"
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 90b885d7ab4..b7c877593b7 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -561,6 +561,37 @@ namespace eval Term {
 	}
     }
 
+    # Translate the color numbers as used in proc _csi_m to a name.
+    proc _color_attr { n } {
+	switch -exact -- $n {
+	    0 {
+		return black
+	    }
+	    1 {
+		return red
+	    }
+	    2 {
+		return green
+	    }
+	    3 {
+		return yellow
+	    }
+	    4 {
+		return blue
+	    }
+	    5 {
+		return magenta
+	    }
+	    6 {
+		return cyan
+	    }
+	    7 {
+		return white
+	    }
+	    default { error "unsupported color number: $n" }
+	}
+    }
+
     # Select Graphic Rendition.
     #
     # https://vt100.net/docs/vt510-rm/SGR.html
@@ -607,13 +638,13 @@ namespace eval Term {
 			set _attrs(invisible) 0
 		    }
 		    30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 {
-			set _attrs(fg) $item
+			set _attrs(fg) [_color_attr [expr $item - 30]]
 		    }
 		    39 {
 			set _attrs(fg) default
 		    }
 		    40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 {
-			set _attrs(bg) $item
+			set _attrs(bg) [_color_attr [expr $item - 40]]
 		    }
 		    49 {
 			set _attrs(bg) default
-- 
2.35.3


      parent reply	other threads:[~2023-05-26 13:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-26 13:02 [pushed 1/3] [gdb/testsuite] Fix reverse attribute in tuiterm Tom de Vries
2023-05-26 13:02 ` [pushed 2/3] [gdb/testsuite] Add invisible and blinking attributes " Tom de Vries
2023-05-26 13:03 ` Tom de Vries [this message]

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=20230526130300.20974-3-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

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

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