@@ -120,6 +120,8 @@ where
120
120
/// Last known position of the cursor. Used to find the new area when the viewport is inlined
121
121
/// and the terminal resized.
122
122
pub last_known_cursor_pos : Position ,
123
+
124
+ use_custom_flush : bool ,
123
125
}
124
126
125
127
impl < B > Drop for Terminal < B >
@@ -158,6 +160,7 @@ where
158
160
viewport_area : Rect :: new ( 0 , cursor_pos. y , 0 , 0 ) ,
159
161
last_known_screen_size : screen_size,
160
162
last_known_cursor_pos : cursor_pos,
163
+ use_custom_flush : true ,
161
164
} )
162
165
}
163
166
@@ -190,15 +193,24 @@ where
190
193
pub fn flush ( & mut self ) -> io:: Result < ( ) > {
191
194
let previous_buffer = & self . buffers [ 1 - self . current ] ;
192
195
let current_buffer = & self . buffers [ self . current ] ;
193
- let updates = diff_buffers ( previous_buffer, current_buffer) ;
194
- if let Some ( DrawCommand :: Put { x, y, .. } ) = updates
195
- . iter ( )
196
- . rev ( )
197
- . find ( |cmd| matches ! ( cmd, DrawCommand :: Put { .. } ) )
198
- {
199
- self . last_known_cursor_pos = Position { x : * x, y : * y } ;
196
+
197
+ if self . use_custom_flush {
198
+ let updates = diff_buffers ( previous_buffer, current_buffer) ;
199
+ if let Some ( DrawCommand :: Put { x, y, .. } ) = updates
200
+ . iter ( )
201
+ . rev ( )
202
+ . find ( |cmd| matches ! ( cmd, DrawCommand :: Put { .. } ) )
203
+ {
204
+ self . last_known_cursor_pos = Position { x : * x, y : * y } ;
205
+ }
206
+ draw ( & mut self . backend , updates. into_iter ( ) )
207
+ } else {
208
+ let updates = previous_buffer. diff ( current_buffer) ;
209
+ if let Some ( ( x, y, _) ) = updates. last ( ) {
210
+ self . last_known_cursor_pos = Position { x : * x, y : * y } ;
211
+ }
212
+ self . backend . draw ( updates. into_iter ( ) )
200
213
}
201
- draw ( & mut self . backend , updates. into_iter ( ) )
202
214
}
203
215
204
216
/// Updates the Terminal so that internal buffers match the requested area.
@@ -408,11 +420,13 @@ fn diff_buffers<'a>(a: &'a Buffer, b: &'a Buffer) -> Vec<DrawCommand<'a>> {
408
420
409
421
let x = row
410
422
. iter ( )
411
- . rposition ( |cell| cell. symbol ( ) != " " || cell. bg != bg)
423
+ . rposition ( |cell| {
424
+ cell. symbol ( ) != " " || cell. bg != bg || cell. modifier != Modifier :: empty ( )
425
+ } )
412
426
. unwrap_or ( 0 ) ;
413
427
last_nonblank_column[ y as usize ] = x as u16 ;
414
- let ( x_abs, y_abs) = a. pos_of ( row_start + x + 1 ) ;
415
428
if x < ( a. area . width as usize ) . saturating_sub ( 1 ) {
429
+ let ( x_abs, y_abs) = a. pos_of ( row_start + x + 1 ) ;
416
430
updates. push ( DrawCommand :: ClearToEnd {
417
431
x : x_abs,
418
432
y : y_abs,
0 commit comments