@@ -5,7 +5,7 @@ use std::{
55
66use crossterm:: {
77 cursor:: MoveTo ,
8- style:: { Attribute , Color , ResetColor , SetAttribute , SetForegroundColor } ,
8+ style:: { Attribute , Color , SetAttribute , SetForegroundColor } ,
99 terminal:: { Clear , ClearType } ,
1010 Command , QueueableCommand ,
1111} ;
@@ -93,20 +93,19 @@ pub fn progress_bar<'a>(
9393 total : u16 ,
9494 line_width : u16 ,
9595) -> io:: Result < ( ) > {
96+ debug_assert ! ( total < 1000 ) ;
9697 debug_assert ! ( progress <= total) ;
9798
9899 const PREFIX : & [ u8 ] = b"Progress: [" ;
99100 const PREFIX_WIDTH : u16 = PREFIX . len ( ) as u16 ;
100- // Leaving the last char empty (_) for `total` > 99.
101- const POSTFIX_WIDTH : u16 = "] xxx/xx exercises_" . len ( ) as u16 ;
101+ const POSTFIX_WIDTH : u16 = "] xxx/xxx" . len ( ) as u16 ;
102102 const WRAPPER_WIDTH : u16 = PREFIX_WIDTH + POSTFIX_WIDTH ;
103103 const MIN_LINE_WIDTH : u16 = WRAPPER_WIDTH + 4 ;
104104
105105 if line_width < MIN_LINE_WIDTH {
106106 writer. write_ascii ( b"Progress: " ) ?;
107107 // Integers are in ASCII.
108- writer. write_ascii ( format ! ( "{progress}/{total}" ) . as_bytes ( ) ) ?;
109- return writer. write_ascii ( b" exercises" ) ;
108+ return writer. write_ascii ( format ! ( "{progress}/{total}" ) . as_bytes ( ) ) ;
110109 }
111110
112111 let stdout = writer. stdout ( ) ;
@@ -133,8 +132,9 @@ pub fn progress_bar<'a>(
133132 }
134133 }
135134
136- stdout. queue ( ResetColor ) ?;
137- write ! ( stdout, "] {progress:>3}/{total} exercises" )
135+ stdout. queue ( SetForegroundColor ( Color :: Reset ) ) ?;
136+
137+ write ! ( stdout, "] {progress:>3}/{total}" )
138138}
139139
140140pub fn clear_terminal ( stdout : & mut StdoutLock ) -> io:: Result < ( ) > {
0 commit comments