]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Handle auto_left_margin in tuiterm
authorTom de Vries <tdevries@suse.de>
Wed, 23 Jul 2025 19:11:41 +0000 (21:11 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 23 Jul 2025 19:11:41 +0000 (21:11 +0200)
The terminal capability bw (aka as auto_left_margin) controls whether a
backspace at the start of a line wraps to the last column of the previous
line.

For tuiterm, we use TERM=ansi, and on linux at least that capability is off.

Consequently the current implementation of Term::_ctl_0x08 doesn't wrap.

Add this capability in Term::_ctl_0x08, and add a unit test.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.tui/tuiterm.exp
gdb/testsuite/lib/tuiterm.exp

index 0e03bfaa8ea46600f81a798422599b7c53e2bde3..e58de688ef29e9866b511915d131b909d8d55890 100644 (file)
@@ -102,7 +102,7 @@ proc test_backspace {} {
 
     Term::_move_cursor 1 2
 
-    Term::_ctl_0x08
+    Term::_ctl_0x08 0
     check "backspace one" {
        "abcdefgh"
        "ijklmnop"
@@ -111,13 +111,22 @@ proc test_backspace {} {
     } 0 2
 
     # Cursor should not move if it is already at column 0.
-    Term::_ctl_0x08
+    Term::_ctl_0x08 0
     check "backspace 2" {
        "abcdefgh"
        "ijklmnop"
        "qrstuvwx"
        "yz01234 "
     } 0 2
+
+    # Cursor should wrap to previous line.
+    Term::_ctl_0x08 1
+    check "backspace 3" {
+       "abcdefgh"
+       "ijklmnop"
+       "qrstuvwx"
+       "yz01234 "
+    } 7 1
 }
 
 proc test_linefeed { } {
index 2268b1e28e0c3fc452d89b53a1969e309cc7a4c6..d4ba1ae11b6b19c13f5bda09851c2c9152e974a3 100644 (file)
@@ -83,14 +83,40 @@ namespace eval Term {
     proc _ctl_0x07 {} {
     }
 
+    # Return 1 if tuiterm has the bw/auto_left_margin enabled.
+    proc _have_bw {} {
+       return 0
+    }
+
     # Backspace.
-    proc _ctl_0x08 {} {
-       _log_cur "Backspace" {
+    proc _ctl_0x08 { {bw -1} } {
+       if { $bw == -1 } {
+           set bw [_have_bw]
+       }
+       _log_cur "Backspace, bw == $bw" {
            variable _cur_col
+           variable _cur_row
+           variable _cols
 
-           if {$_cur_col > 0} {
+           if { $_cur_col > 0 } {
+               # No wrapping needed.
                incr _cur_col -1
+               return
            }
+
+           if { ! $bw } {
+               # Wrapping not enabled.
+               return
+           }
+
+           if { $_cur_row == 0 } {
+               # Can't wrap.
+               return
+           }
+
+           # Wrap to previous line.
+           set _cur_col [expr $_cols - 1]
+           incr _cur_row -1
        }
     }