File tree Expand file tree Collapse file tree 2 files changed +22
-16
lines changed
Expand file tree Collapse file tree 2 files changed +22
-16
lines changed Original file line number Diff line number Diff line change @@ -36,3 +36,15 @@ pub(crate) fn enable_windows_ansi() -> bool {
3636pub ( crate ) fn enable_windows_ansi ( ) -> bool {
3737 true
3838}
39+
40+ pub ( crate ) fn insert_codes ( rendered : & str , up_lines : Option < usize > ) -> String {
41+ let mut buf = String :: with_capacity ( rendered. len ( ) + 40 ) ;
42+ if let Some ( up_lines) = up_lines {
43+ buf. push_str ( & up_n_lines_and_home ( up_lines) ) ;
44+ }
45+ buf. push_str ( DISABLE_LINE_WRAP ) ;
46+ buf. push_str ( CLEAR_TO_END_OF_SCREEN ) ;
47+ buf. push_str ( rendered) ;
48+ buf. push_str ( ENABLE_LINE_WRAP ) ;
49+ buf
50+ }
Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ pub mod _changelog {
229229 use super :: * ; // so that hyperlinks work
230230}
231231
232+ use crate :: ansi:: insert_codes;
232233pub use crate :: destination:: Destination ;
233234pub use crate :: helpers:: * ;
234235pub use crate :: options:: Options ;
@@ -746,22 +747,15 @@ impl<M: Model> InnerView<M> {
746747 // be simpler?)
747748 rendered. pop ( ) ;
748749 }
749- let mut buf = String :: new ( ) ;
750- if let State :: ProgressDrawn {
751- ref last_drawn_string,
752- cursor_y,
753- ..
754- } = self . state
755- {
756- if * last_drawn_string == rendered {
757- return Ok ( ( ) ) ;
758- }
759- buf. push_str ( & ansi:: up_n_lines_and_home ( cursor_y) ) ;
760- }
761- buf. push_str ( ansi:: DISABLE_LINE_WRAP ) ;
762- buf. push_str ( ansi:: CLEAR_TO_END_OF_SCREEN ) ;
763- buf. push_str ( & rendered) ;
764- self . write_output ( & buf) ;
750+ let up_lines = match self . state {
751+ State :: ProgressDrawn {
752+ ref last_drawn_string,
753+ cursor_y,
754+ ..
755+ } if * last_drawn_string != rendered => Some ( cursor_y) ,
756+ _ => None ,
757+ } ;
758+ self . write_output ( & insert_codes ( & rendered, up_lines) ) ;
765759 let cursor_y = rendered. as_bytes ( ) . iter ( ) . filter ( |b| * * b == b'\n' ) . count ( ) ;
766760 self . state = State :: ProgressDrawn {
767761 last_drawn_time : now,
You can’t perform that action at this time.
0 commit comments