File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,8 +52,8 @@ pub enum CheckProgress {
5252pub struct AppState {
5353 current_exercise_ind : usize ,
5454 exercises : Vec < Exercise > ,
55- // Caches the number of done exercises to avoid iterating over all exercises every time.
56- n_done : u16 ,
55+ // Cache the number of done exercises to avoid iterating over all exercises every time.
56+ n_done : u32 ,
5757 final_message : & ' static str ,
5858 state_file : File ,
5959 // Preallocated buffer for reading and writing the state file.
@@ -191,13 +191,13 @@ impl AppState {
191191 }
192192
193193 #[ inline]
194- pub fn n_done ( & self ) -> u16 {
194+ pub fn n_done ( & self ) -> u32 {
195195 self . n_done
196196 }
197197
198198 #[ inline]
199- pub fn n_pending ( & self ) -> u16 {
200- self . exercises . len ( ) as u16 - self . n_done
199+ pub fn n_pending ( & self ) -> u32 {
200+ self . exercises . len ( ) as u32 - self . n_done
201201 }
202202
203203 #[ inline]
Original file line number Diff line number Diff line change @@ -229,7 +229,7 @@ impl<'a> ListState<'a> {
229229 progress_bar (
230230 & mut MaxLenWriter :: new ( stdout, self . term_width as usize ) ,
231231 self . app_state . n_done ( ) ,
232- self . app_state . exercises ( ) . len ( ) as u16 ,
232+ self . app_state . exercises ( ) . len ( ) as u32 ,
233233 self . term_width ,
234234 ) ?;
235235 next_ln ( stdout) ?;
Original file line number Diff line number Diff line change @@ -193,8 +193,8 @@ impl Drop for ProgressCounter<'_, '_> {
193193
194194pub fn progress_bar < ' a > (
195195 writer : & mut impl CountedWrite < ' a > ,
196- progress : u16 ,
197- total : u16 ,
196+ progress : u32 ,
197+ total : u32 ,
198198 term_width : u16 ,
199199) -> io:: Result < ( ) > {
200200 const PREFIX : & [ u8 ] = b"Progress: [" ;
@@ -215,10 +215,9 @@ pub fn progress_bar<'a>(
215215 let stdout = writer. stdout ( ) ;
216216 stdout. write_all ( PREFIX ) ?;
217217
218- let width = term_width - WRAPPER_WIDTH ;
219- // Use u32 to prevent the intermediate multiplication from overflowing u16
220- let filled = ( width as u32 * progress as u32 ) / total as u32 ;
221- let filled = filled as u16 ;
218+ // Use u32 to prevent the intermediate multiplication from overflowing
219+ let width = u32:: from ( term_width - WRAPPER_WIDTH ) ;
220+ let filled = ( width * progress) / total;
222221
223222 stdout. queue ( SetForegroundColor ( Color :: Green ) ) ?;
224223 for _ in 0 ..filled {
Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ impl<'a> WatchState<'a> {
245245 progress_bar (
246246 stdout,
247247 self . app_state . n_done ( ) ,
248- self . app_state . exercises ( ) . len ( ) as u16 ,
248+ self . app_state . exercises ( ) . len ( ) as u32 ,
249249 self . term_width ,
250250 ) ?;
251251
You can’t perform that action at this time.
0 commit comments