mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-28 09:14:04 +00:00
progress: use clamp()
for readability
This was actually what I meant in my code-review comment but I used the wrong word ("clip") :) I wasn't going to bother changing it, but Clippy nightly just started warning about it.
This commit is contained in:
parent
597e10103f
commit
95638d453c
1 changed files with 1 additions and 1 deletions
|
@ -67,7 +67,7 @@ impl Drop for Progress<'_> {
|
|||
fn draw_progress(progress: f32, buffer: &mut String, width: usize) {
|
||||
const CHARS: [char; 9] = [' ', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'];
|
||||
const RESOLUTION: usize = CHARS.len() - 1;
|
||||
let ticks = (width as f32 * progress.min(1.0).max(0.0) * RESOLUTION as f32).round() as usize;
|
||||
let ticks = (width as f32 * progress.clamp(0.0, 1.0) * RESOLUTION as f32).round() as usize;
|
||||
let whole = ticks / RESOLUTION;
|
||||
for _ in 0..whole {
|
||||
buffer.push(CHARS[CHARS.len() - 1]);
|
||||
|
|
Loading…
Reference in a new issue