[2/6,gdb/testsuite] Factor out Term::_wrap_cursor

Message ID 20230522131545.12291-4-tdevries@suse.de
State New
Headers
Series Introduce ansi-for-tui |

Commit Message

Tom de Vries May 22, 2023, 1:15 p.m. UTC
  Factor out new proc Term::_wrap_cursor out of proc Term::_insert.

Tested on x86_64-linux.
---
 gdb/testsuite/lib/tuiterm.exp | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
  

Patch

diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 5c0be85ee73..e52cb3e5b6d 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -609,6 +609,18 @@  namespace eval Term {
 	}
     }
 
+    # Set cursor to col 0 on the next line.  If we run off screen, error out.
+    proc _wrap_cursor {} {
+	variable _cur_col
+	variable _cur_row
+	variable _rows
+	set _cur_col 0
+	incr _cur_row
+	if {$_cur_row >= $_rows} {
+	    error "FIXME scroll"
+	}
+    }
+
     # Insert string at the cursor location.
     proc _insert {str} {
 	_log_cur "Inserted string '$str'" {
@@ -616,7 +628,6 @@  namespace eval Term {
 
 	    variable _cur_col
 	    variable _cur_row
-	    variable _rows
 	    variable _cols
 	    variable _attrs
 	    variable _chars
@@ -626,11 +637,7 @@  namespace eval Term {
 		    set _chars($_cur_col,$_cur_row) [list $char $lattr]
 		    incr _cur_col
 		    if {$_cur_col >= $_cols} {
-			set _cur_col 0
-			incr _cur_row
-			if {$_cur_row >= $_rows} {
-			    error "FIXME scroll"
-			}
+			_wrap_cursor
 		    }
 		}
 	    }