@@ -120,6 +120,8 @@ where
120120 /// Last known position of the cursor. Used to find the new area when the viewport is inlined
121121 /// and the terminal resized.
122122 pub last_known_cursor_pos : Position ,
123+
124+ use_custom_flush : bool ,
123125}
124126
125127impl < B > Drop for Terminal < B >
@@ -158,6 +160,7 @@ where
158160 viewport_area : Rect :: new ( 0 , cursor_pos. y , 0 , 0 ) ,
159161 last_known_screen_size : screen_size,
160162 last_known_cursor_pos : cursor_pos,
163+ use_custom_flush : true ,
161164 } )
162165 }
163166
@@ -190,15 +193,24 @@ where
190193 pub fn flush ( & mut self ) -> io:: Result < ( ) > {
191194 let previous_buffer = & self . buffers [ 1 - self . current ] ;
192195 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 ( ) )
200213 }
201- draw ( & mut self . backend , updates. into_iter ( ) )
202214 }
203215
204216 /// 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>> {
408420
409421 let x = row
410422 . iter ( )
411- . rposition ( |cell| cell. symbol ( ) != " " || cell. bg != bg)
423+ . rposition ( |cell| {
424+ cell. symbol ( ) != " " || cell. bg != bg || cell. modifier != Modifier :: empty ( )
425+ } )
412426 . unwrap_or ( 0 ) ;
413427 last_nonblank_column[ y as usize ] = x as u16 ;
414- let ( x_abs, y_abs) = a. pos_of ( row_start + x + 1 ) ;
415428 if x < ( a. area . width as usize ) . saturating_sub ( 1 ) {
429+ let ( x_abs, y_abs) = a. pos_of ( row_start + x + 1 ) ;
416430 updates. push ( DrawCommand :: ClearToEnd {
417431 x : x_abs,
418432 y : y_abs,
0 commit comments