A rust crate i use for my projects
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update remaining time calculator, its more accurate now. Also changed styling

MrSnowy f7f11f7b a903140e

+10 -17
+10 -17
src/lib.rs
··· 24 24 loop { 25 25 let done = done.load(Ordering::Relaxed); 26 26 27 - // let total = total.load(Ordering::Relaxed); 28 - // let size = size.load(Ordering::Relaxed); 29 - 30 27 // some work here 31 28 let procentage_f = done as f32 / total as f32; 32 29 let procentage = (procentage_f * 100f32).round(); 33 30 // print!("{}") 34 - let done_count = size as f32 * procentage_f; 35 - // let todo_count = size - done_count.round(); 31 + let done_count = (size as f32 * procentage_f) as u64; 36 32 37 33 let mut string = "\r".to_string(); 38 34 string.push_str(&title); 39 - string.push_str(" || "); 35 + string.push_str(" [[ "); 40 36 41 37 if done == total { 42 38 string.push_str("\x1b[32m"); 43 39 } 44 40 45 41 for each in 0..size { 46 - if each <= done_count.round() as u8 { 42 + if each as u64 <= done_count { 47 43 string.push('■'); 48 44 } else { 49 45 string.push('·'); ··· 56 52 57 53 // Guestimate remaining time 58 54 let going_for = started_at.elapsed().as_secs_f32(); 59 - let still_todo = 100f32 - procentage; 60 - let time_per_percentage = procentage / going_for; 61 - let remaining_time = (still_todo / time_per_percentage).ceil(); 55 + let time_per_num = (done as f32 / going_for) / 100f32; 56 + let remaining_time = (time_per_num * (total - done) as f32).ceil() as u64; 62 57 63 58 if done == total { 64 59 string.push_str(&format!( 65 - " {}/{} {}% || in {}s! \n", 60 + " {}/{} {}% ]] in {}s! \n", 66 61 done, 67 62 total, 68 63 procentage, ··· 70 65 )); 71 66 } else { 72 67 string.push_str(&format!( 73 - " {}/{} {}% || {}s ", 68 + " {}/{} {}% ]] {}s ", 74 69 done, total, procentage, remaining_time 75 70 )); 76 71 } ··· 78 73 print!("{string}"); 79 74 80 75 if done >= total { 81 - // println!("Stopping!"); 82 76 break; 83 77 } 84 - // print!("sleeping"); 85 78 thread::sleep(update_time); 86 79 } 87 80 }); ··· 104 97 105 98 start_progress_bar( 106 99 &value, 107 - 100, 100 + 1811, 108 101 50, 109 102 "Being silly", 110 103 now, 111 - Duration::from_millis(1), 104 + Duration::from_millis(30), 112 105 ); 113 106 114 - for _ in 0..=100 { 107 + for _ in 0..=12811 { 115 108 value.fetch_add(1, Ordering::Relaxed); 116 109 117 110 thread::sleep(Duration::from_millis(100));