gdb/testing/tui: add new _csi_{L,S,T}
authorAndrew Burgess <aburgess@redhat.com>
Wed, 26 Jan 2022 18:41:59 +0000 (18:41 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 1 Apr 2022 15:22:01 +0000 (16:22 +0100)
This patch was original part of this series:

  https://sourceware.org/pipermail/gdb-patches/2022-March/186429.html
  https://sourceware.org/pipermail/gdb-patches/2022-March/186433.html

I've pulled this out as it might be useful ahead of the bigger series
being merged.

This commit adds:

  _csi_L - insert line
  _csi_S - pan down
  _csi_T - pan up

gdb/testsuite/gdb.tui/tuiterm.exp
gdb/testsuite/lib/tuiterm.exp

index c82db21a92b04d5d4d144ac38dea5e3d2c4bdf6a..98f1cd7fe8c37041978b496aa19ae573952790b0 100644 (file)
@@ -179,6 +179,60 @@ proc test_insert_characters { } {
     } 0 1
 }
 
+proc test_pan_down { } {
+    Term::_move_cursor 1 2
+    Term::_csi_S
+    check "pan down, default arg" {
+       "ijklmnop"
+       "qrstuvwx"
+       "yz01234 "
+       "        "
+    } 1 2
+
+    Term::_csi_S 2
+    check "pan down, explicit arg" {
+       "yz01234 "
+       "        "
+       "        "
+       "        "
+    } 1 2
+
+    Term::_csi_S 100
+    check "pan down, excessive arg" {
+       "        "
+       "        "
+       "        "
+       "        "
+    } 1 2
+}
+
+proc test_pan_up { } {
+    Term::_move_cursor 1 2
+    Term::_csi_T
+    check "pan down, default arg" {
+       "        "
+       "abcdefgh"
+       "ijklmnop"
+       "qrstuvwx"
+    } 1 2
+
+    Term::_csi_T 2
+    check "pan down, explicit arg" {
+       "        "
+       "        "
+       "        "
+       "abcdefgh"
+    } 1 2
+
+    Term::_csi_T 100
+    check "pan down, excessive arg" {
+       "        "
+       "        "
+       "        "
+       "        "
+    } 1 2
+}
+
 proc test_cursor_up { } {
     Term::_move_cursor 2 3
 
@@ -594,6 +648,34 @@ proc test_vertical_line_position_absolute { } {
     } 2 3
 }
 
+proc test_insert_line { } {
+    Term::_move_cursor 2 1
+    Term::_csi_L
+    check "insert line, default param" {
+       "abcdefgh"
+       "        "
+       "ijklmnop"
+       "qrstuvwx"
+    } 2 1
+
+    Term::_move_cursor 2 0
+    Term::_csi_L 2
+    check "insert line, explicit param" {
+       "        "
+       "        "
+       "abcdefgh"
+       "        "
+    } 2 0
+
+    Term::_csi_L 12
+    check "insert line, insert more lines than display has" {
+       "        "
+       "        "
+       "        "
+       "        "
+    } 2 0
+}
+
 # Run proc TEST_PROC_NAME with a "small" terminal.
 
 proc run_one_test_small { test_proc_name } {
@@ -632,6 +714,9 @@ foreach_with_prefix test {
     test_erase_character
     test_repeat
     test_vertical_line_position_absolute
+    test_insert_line
+    test_pan_up
+    test_pan_down
 } {
     run_one_test_small $test
 }
index 9053f7dba6a9440c6d5f52833d45e55edb2b78c0..e660840eed9ef2315845728544fa97e917329441 100644 (file)
@@ -324,6 +324,33 @@ namespace eval Term {
        }
     }
 
+    # Insert Line
+    #
+    # https://vt100.net/docs/vt510-rm/IL.html
+    proc _csi_L {args} {
+       set arg [_default [lindex $args 0] 1]
+
+       _log_cur "Insert Line ($arg)" {
+           variable _cur_col
+           variable _cur_row
+           variable _rows
+           variable _cols
+           variable _chars
+
+           set y [expr $_rows - 2]
+           set next_y [expr $y + $arg]
+           while {$y >= $_cur_row} {
+               for {set x 0} {$x < $_cols} {incr x} {
+                   set _chars($x,$next_y) $_chars($x,$y)
+               }
+               incr y -1
+               incr next_y -1
+           }
+
+           _clear_lines $_cur_row [expr $_cur_row + $arg]
+       }
+    }
+
     # Delete line.
     #
     # https://vt100.net/docs/vt510-rm/DL.html
@@ -376,6 +403,74 @@ namespace eval Term {
        }
     }
 
+    # Pan Down
+    #
+    # https://vt100.net/docs/vt510-rm/SU.html
+    proc _csi_S {args} {
+       set count [_default [lindex $args 0] 1]
+
+       _log_cur "Pan Down ($count)" {
+           variable _cur_col
+           variable _cur_row
+           variable _cols
+           variable _rows
+           variable _chars
+
+           # The following code is written without consideration for
+           # the scroll margins.  At this time this comment was
+           # written the tuiterm library doesn't support the scroll
+           # margins.  If/when that changes, then the following will
+           # need to be updated.
+
+           set dy 0
+           set y $count
+
+           while {$y < $_rows} {
+               for {set x 0} {$x < $_cols} {incr x} {
+                   set _chars($x,$dy) $_chars($x,$y)
+               }
+               incr y 1
+               incr dy 1
+           }
+
+           _clear_lines $dy $_rows
+       }
+    }
+
+    # Pan Up
+    #
+    # https://vt100.net/docs/vt510-rm/SD.html
+    proc _csi_T {args} {
+       set count [_default [lindex $args 0] 1]
+
+       _log_cur "Pan Up ($count)" {
+           variable _cur_col
+           variable _cur_row
+           variable _cols
+           variable _rows
+           variable _chars
+
+           # The following code is written without consideration for
+           # the scroll margins.  At this time this comment was
+           # written the tuiterm library doesn't support the scroll
+           # margins.  If/when that changes, then the following will
+           # need to be updated.
+
+           set y [expr $_rows - $count]
+           set dy $_rows
+
+           while {$dy >= $count} {
+               for {set x 0} {$x < $_cols} {incr x} {
+                   set _chars($x,$dy) $_chars($x,$y)
+               }
+               incr y -1
+               incr dy -1
+           }
+
+           _clear_lines 0 $count
+       }
+    }
+
     # Erase chars.
     #
     # https://vt100.net/docs/vt510-rm/ECH.html