summaryrefslogtreecommitdiff
path: root/src/progress_bar.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-08-24 17:17:56 +0200
committermo8it <mo8it@proton.me>2024-08-24 17:17:56 +0200
commitb779c431268da50989257056d21a870a61a1702e (patch)
treee4cb739dcae7dd885bac0e325f09a12ba3d89519 /src/progress_bar.rs
parent4e12725616abe1918d6a4f21b23288dfac237cc4 (diff)
Almost done with list display
Diffstat (limited to 'src/progress_bar.rs')
-rw-r--r--src/progress_bar.rs53
1 files changed, 0 insertions, 53 deletions
diff --git a/src/progress_bar.rs b/src/progress_bar.rs
deleted file mode 100644
index 837c4c7..0000000
--- a/src/progress_bar.rs
+++ /dev/null
@@ -1,53 +0,0 @@
-use std::io::{self, StdoutLock, Write};
-
-use crossterm::{
- style::{Color, ResetColor, SetForegroundColor},
- QueueableCommand,
-};
-
-const PREFIX: &[u8] = b"Progress: [";
-const PREFIX_WIDTH: u16 = PREFIX.len() as u16;
-// Leaving the last char empty (_) for `total` > 99.
-const POSTFIX_WIDTH: u16 = "] xxx/xx exercises_".len() as u16;
-const WRAPPER_WIDTH: u16 = PREFIX_WIDTH + POSTFIX_WIDTH;
-const MIN_LINE_WIDTH: u16 = WRAPPER_WIDTH + 4;
-
-/// Terminal progress bar to be used when not using Ratataui.
-pub fn progress_bar(
- stdout: &mut StdoutLock,
- progress: u16,
- total: u16,
- line_width: u16,
-) -> io::Result<()> {
- debug_assert!(progress <= total);
-
- if line_width < MIN_LINE_WIDTH {
- return write!(stdout, "Progress: {progress}/{total} exercises");
- }
-
- stdout.write_all(PREFIX)?;
-
- let width = line_width - WRAPPER_WIDTH;
- let filled = (width * progress) / total;
-
- stdout.queue(SetForegroundColor(Color::Green))?;
- for _ in 0..filled {
- stdout.write_all(b"#")?;
- }
-
- if filled < width {
- stdout.write_all(b">")?;
- }
-
- let width_minus_filled = width - filled;
- if width_minus_filled > 1 {
- let red_part_width = width_minus_filled - 1;
- stdout.queue(SetForegroundColor(Color::Red))?;
- for _ in 0..red_part_width {
- stdout.write_all(b"-")?;
- }
- }
-
- stdout.queue(ResetColor)?;
- write!(stdout, "] {progress:>3}/{total} exercises")
-}