@@ -313,14 +313,6 @@ pub(crate) struct ProgressDrawState {
313313}
314314
315315impl ProgressDrawState {
316- pub fn clear_term ( & self , term : & Term ) -> io:: Result < ( ) > {
317- term. clear_last_lines ( self . lines . len ( ) - self . orphan_lines )
318- }
319-
320- pub fn move_cursor ( & self , term : & Term ) -> io:: Result < ( ) > {
321- term. move_cursor_up ( self . lines . len ( ) - self . orphan_lines )
322- }
323-
324316 pub fn draw_to_term ( & self , term : & Term ) -> io:: Result < ( ) > {
325317 for line in & self . lines {
326318 term. write_line ( line) ?;
@@ -428,7 +420,7 @@ impl ProgressDrawTarget {
428420 ProgressDrawTarget {
429421 kind : ProgressDrawTargetKind :: Term {
430422 term,
431- last_state : None ,
423+ last_line_count : 0 ,
432424 rate,
433425 last_draw : Instant :: now ( ) - rate,
434426 } ,
@@ -474,7 +466,7 @@ impl ProgressDrawTarget {
474466 match self . kind {
475467 ProgressDrawTargetKind :: Term {
476468 ref term,
477- ref mut last_state ,
469+ ref mut last_line_count ,
478470 rate,
479471 ref mut last_draw,
480472 } => {
@@ -483,16 +475,14 @@ impl ProgressDrawTarget {
483475 || rate == Duration :: from_secs ( 0 )
484476 || last_draw. elapsed ( ) > rate
485477 {
486- if let Some ( ref last_state) = * last_state {
487- if !draw_state. lines . is_empty ( ) && draw_state. move_cursor {
488- last_state. move_cursor ( term) ?;
489- } else {
490- last_state. clear_term ( term) ?;
491- }
478+ if !draw_state. lines . is_empty ( ) && draw_state. move_cursor {
479+ term. move_cursor_up ( * last_line_count) ?;
480+ } else {
481+ term. clear_last_lines ( * last_line_count) ?;
492482 }
493483 draw_state. draw_to_term ( term) ?;
494484 term. flush ( ) ?;
495- * last_state = Some ( draw_state) ;
485+ * last_line_count = draw_state. lines . len ( ) - draw_state . orphan_lines ;
496486 * last_draw = Instant :: now ( ) ;
497487 }
498488 }
@@ -534,7 +524,7 @@ impl ProgressDrawTarget {
534524pub ( crate ) enum ProgressDrawTargetKind {
535525 Term {
536526 term : Term ,
537- last_state : Option < ProgressDrawState > ,
527+ last_line_count : usize ,
538528 rate : Duration ,
539529 last_draw : Instant ,
540530 } ,
0 commit comments