]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Add Term::get_string_with_attrs in tuiterm
authorTom de Vries <tdevries@suse.de>
Thu, 24 Jul 2025 10:06:40 +0000 (12:06 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 24 Jul 2025 10:06:40 +0000 (12:06 +0200)
While reading a gdb.log for test-case gdb.tui/main-2.exp, I noticed that this
line was somewhat hard to read:
...
screen line 6: '<fg:cyan><intensity:bold>|<fg:default><intensity:normal>B+>    21 <reverse:1>  return 0;<reverse:0>                                                         <fg:cyan><intensity:bold>|<fg:default><intensity:normal>'
...
because of the border attributes.

Then I realized that the test-case is only interested in the text between the
borders, so I added a proc Term::get_string_with_attrs that allows me to drop
the borders, getting us instead:
...
screen line 6: 'B+>    21 <reverse:1>  return 0;<reverse:0>                                                         '
...

Tested on aarch64-linux.

gdb/testsuite/gdb.tui/main-2.exp
gdb/testsuite/lib/tuiterm.exp

index 2b0fb6bd00397b0986bf2e2cdd1ca0225111b7da..71ad03b73fcec3d6d140fc170f7ed20392c7f084 100644 (file)
@@ -41,7 +41,7 @@ if {![Term::enter_tui]} {
 set line "  return 0;"
 set nr [gdb_get_line_number $line]
 
-set screen_line [Term::get_line_with_attrs 6]
+set screen_line [Term::get_string_with_attrs 6 1 79]
 verbose -log "screen line 6: '$screen_line'"
 gdb_assert { [regexp "$nr <reverse:1>$line<reverse:0>" $screen_line] } \
     "highlighted line in middle of source window"
index 8ea8ebecd6b010908516d2afb7ff041a6072905c..cc8e852690add418f20ed37026154119171c4292 100644 (file)
@@ -1009,10 +1009,10 @@ namespace eval Term {
        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} {
+    # Return the text of screen line N.  Lines are 0-based.  Start at column
+    # X.  If C is non-empty, stop before column C.  Columns are also
+    # zero-based.  If ATTRS, annotate with attributes.
+    proc get_string {n x c {attrs 0}} {
        variable _rows
        # This can happen during resizing, if the cursor seems to
        # temporarily be off-screen.
@@ -1024,7 +1024,6 @@ namespace eval Term {
        variable _cols
        variable _chars
        set c [_default $c $_cols]
-       set x 0
        if { $attrs } {
            _reset_attrs line_attrs
        }
@@ -1044,6 +1043,20 @@ namespace eval Term {
        return $result
     }
 
+    # Return the text of screen line N.  Lines are 0-based.  Start at column
+    # X.  If C is non-empty, stop before column C.  Columns are also
+    # zero-based. Annotate with attributes.
+    proc get_string_with_attrs { n x c } {
+       return [get_string $n $x $c 1]
+    }
+
+    # Return the text of screen line N.  Lines are 0-based.  If C is
+    # non-empty, stop before column C.  Columns are also zero-based. If
+    # ATTRS, annotate with attributes.
+    proc get_line_1 {n c attrs} {
+       return [get_string $n 0 $c $attrs]
+    }
+
     # 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.