@@ -111,14 +111,9 @@ impl ConsoleInner {
111111 self . cursor_depth += 1 ;
112112 }
113113
114- fn move_char_right ( & mut self ) {
115- self . col += 1 ;
116- }
117-
118- fn move_char_down ( & mut self ) {
119- self . row += 1 ;
120- }
121-
114+ /// Move the cursor relative to the current location.
115+ ///
116+ /// Clamps to the visible screen.
122117 fn move_cursor_relative ( & mut self , rows : isize , cols : isize ) {
123118 self . row += rows;
124119 self . col += cols;
@@ -136,6 +131,9 @@ impl ConsoleInner {
136131 }
137132 }
138133
134+ /// Move the cursor to the given location.
135+ ///
136+ /// Clamps to the visible screen.
139137 fn move_cursor_absolute ( & mut self , rows : isize , cols : isize ) {
140138 // move it
141139 self . row = rows;
@@ -144,10 +142,15 @@ impl ConsoleInner {
144142 self . move_cursor_relative ( 0 , 0 ) ;
145143 }
146144
145+ /// Move the cursor to 0,0
147146 fn home ( & mut self ) {
148147 self . move_cursor_absolute ( 0 , 0 ) ;
149148 }
150149
150+ /// If we are currently position off-screen, scroll and fix that.
151+ ///
152+ /// We defer this so you can write the last char on the last line without
153+ /// causing it to scroll pre-emptively.
151154 fn scroll_as_required ( & mut self ) {
152155 assert ! ( self . row <= self . height) ;
153156 if self . col >= self . width {
@@ -160,6 +163,7 @@ impl ConsoleInner {
160163 }
161164 }
162165
166+ /// Blank the screen
163167 fn clear ( & mut self ) {
164168 for row in 0 ..self . height {
165169 for col in 0 ..self . width {
@@ -233,7 +237,6 @@ impl ConsoleInner {
233237 /// The bottom line will be all space characters.
234238 fn scroll_page ( & mut self ) {
235239 let row_len_bytes = self . width * 2 ;
236- self . cursor_disable ( ) ;
237240 unsafe {
238241 // Scroll rows[1..=height-1] to become rows[0..=height-2].
239242 core:: ptr:: copy (
@@ -242,7 +245,6 @@ impl ConsoleInner {
242245 ( row_len_bytes * ( self . height - 1 ) ) as usize ,
243246 ) ;
244247 }
245- self . cursor_enable ( ) ;
246248 // Blank the bottom line of the screen (rows[height-1]).
247249 for col in 0 ..self . width {
248250 self . write_at ( self . height - 1 , col, b' ' , false ) ;
@@ -413,7 +415,7 @@ impl vte::Perform for ConsoleInner {
413415 fn print ( & mut self , ch : char ) {
414416 self . scroll_as_required ( ) ;
415417 self . write ( Self :: map_char_to_glyph ( ch) ) ;
416- self . move_char_right ( ) ;
418+ self . col += 1 ;
417419 }
418420
419421 /// Execute a C0 or C1 control function.
@@ -433,12 +435,14 @@ impl vte::Perform for ConsoleInner {
433435 }
434436 b'\n' => {
435437 self . col = 0 ;
436- self . move_char_down ( ) ;
438+ self . row += 1 ;
437439 }
438440 _ => {
439441 // ignore unknown C0 or C1 control code
440442 }
441443 }
444+ // We may now be off-screen, but that's OK because we will scroll before
445+ // we print the next thing.
442446 }
443447
444448 /// A final character has arrived for a CSI sequence
@@ -454,19 +458,8 @@ impl vte::Perform for ConsoleInner {
454458 action : char ,
455459 ) {
456460 // Just in case you want a single parameter, here it is
457- let mut first = params
458- . iter ( )
459- . next ( )
460- . and_then ( |s| s. first ( ) )
461- . unwrap_or ( & 1 )
462- . clone ( ) as isize ;
463- let mut second = params
464- . iter ( )
465- . skip ( 1 )
466- . next ( )
467- . and_then ( |s| s. first ( ) )
468- . unwrap_or ( & 1 )
469- . clone ( ) as isize ;
461+ let mut first = * params. iter ( ) . next ( ) . and_then ( |s| s. first ( ) ) . unwrap_or ( & 1 ) as isize ;
462+ let mut second = * params. iter ( ) . nth ( 1 ) . and_then ( |s| s. first ( ) ) . unwrap_or ( & 1 ) as isize ;
470463
471464 match action {
472465 'm' => {
0 commit comments