summaryrefslogtreecommitdiff
path: root/src/term.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-10-10 19:43:35 +0200
committermo8it <mo8it@proton.me>2024-10-10 19:43:35 +0200
commit685e069c58ef02dae65381974722315ee8c84e8b (patch)
treec2a319c398fb7226b4109b81bdb00f419c689435 /src/term.rs
parentd3f819f86f0fd7e67e9b995034947a65961cab34 (diff)
First PR review changes
Diffstat (limited to 'src/term.rs')
-rw-r--r--src/term.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/term.rs b/src/term.rs
index 67ace4b..31a951d 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -89,34 +89,35 @@ impl<'a> CountedWrite<'a> for StdoutLock<'a> {
}
}
-/// Simple terminal progress bar
+/// Simple terminal progress bar.
pub fn progress_bar<'a>(
writer: &mut impl CountedWrite<'a>,
progress: u16,
total: u16,
- line_width: u16,
+ term_width: u16,
) -> io::Result<()> {
- progress_bar_with_success(writer, 0, 0, progress, total, line_width)
+ progress_bar_with_success(writer, 0, 0, progress, total, term_width)
}
-/// Terminal progress bar with three states (pending + failed + success)
+
+/// Terminal progress bar with three states (pending + failed + success).
pub fn progress_bar_with_success<'a>(
writer: &mut impl CountedWrite<'a>,
pending: u16,
failed: u16,
success: u16,
total: u16,
- line_width: u16,
+ term_width: u16,
) -> io::Result<()> {
debug_assert!(total < 1000);
- debug_assert!((pending + failed + success) <= total);
+ debug_assert!(pending + failed + success <= total);
const PREFIX: &[u8] = b"Progress: [";
const PREFIX_WIDTH: u16 = PREFIX.len() as u16;
const POSTFIX_WIDTH: u16 = "] xxx/xxx".len() as u16;
const WRAPPER_WIDTH: u16 = PREFIX_WIDTH + POSTFIX_WIDTH;
- const MIN_LINE_WIDTH: u16 = WRAPPER_WIDTH + 4;
+ const MIN_TERM_WIDTH: u16 = WRAPPER_WIDTH + 4;
- if line_width < MIN_LINE_WIDTH {
+ if term_width < MIN_TERM_WIDTH {
writer.write_ascii(b"Progress: ")?;
// Integers are in ASCII.
return writer.write_ascii(format!("{}/{total}", failed + success).as_bytes());
@@ -125,7 +126,7 @@ pub fn progress_bar_with_success<'a>(
let stdout = writer.stdout();
stdout.write_all(PREFIX)?;
- let width = line_width - WRAPPER_WIDTH;
+ let width = term_width - WRAPPER_WIDTH;
let mut failed_end = (width * failed) / total;
let mut success_end = (width * (failed + success)) / total;
let mut pending_end = (width * (failed + success + pending)) / total;