mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Add "exercises" to the end of the progress bar
This commit is contained in:
parent
af85f2036c
commit
a8ddc07a9a
|
@ -7,13 +7,13 @@ pub fn progress_bar(progress: u16, total: u16, line_width: u16) -> Result<String
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Progress: [".len() == 11
|
// "Progress: [".len() == 11
|
||||||
// "] xxx/xxx".len() == 9
|
// "] xxx/xx exercises_".len() == 19 (leaving the last char empty for `total` > 99)
|
||||||
// 11 + 9 = 20
|
// 11 + 19 = 30
|
||||||
let wrapper_width = 20;
|
let wrapper_width = 30;
|
||||||
|
|
||||||
// If the line width is too low for a progress bar, just show the ratio.
|
// If the line width is too low for a progress bar, just show the ratio.
|
||||||
if line_width < wrapper_width + 4 {
|
if line_width < wrapper_width + 4 {
|
||||||
return Ok(format!("Progress: {progress}/{total}"));
|
return Ok(format!("Progress: {progress}/{total} exercises"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut line = String::with_capacity(usize::from(line_width));
|
let mut line = String::with_capacity(usize::from(line_width));
|
||||||
|
@ -34,7 +34,7 @@ pub fn progress_bar(progress: u16, total: u16, line_width: u16) -> Result<String
|
||||||
line.push(' ');
|
line.push(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
line.write_fmt(format_args!("] {progress:>3}/{total:<3}"))
|
line.write_fmt(format_args!("] {progress:>3}/{total} exercises"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Ok(line)
|
Ok(line)
|
||||||
|
|
Loading…
Reference in a new issue