Skip to content

Commit

Permalink
Show scanned files count
Browse files Browse the repository at this point in the history
  • Loading branch information
funbiscuit committed Oct 13, 2022
1 parent fc8c36f commit dbac5a1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
23 changes: 20 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ byte-unit = { version = "4.0", default-features = false, features = ["std"] }
clap = { version = "4.0.0-rc.2", features = ["derive"] }
crossterm = { version = "0.25", features = ["serde"] }
derivative = "2.2.0"
num-format = "0.4.3"
tui = { version = "0.19", default-features = false, features = ["crossterm"] }
unicode-width = "0.1.10"
29 changes: 26 additions & 3 deletions cli/src/progressbar.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use num_format::{CustomFormat, Grouping};
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Style};
Expand All @@ -17,9 +18,14 @@ pub struct BarItem {
#[derive(Clone, Debug, Default)]
pub struct ProgressBar {
parts: Vec<BarItem>,
files: u32,
}

impl ProgressBar {
pub fn files(mut self, files: u32) -> ProgressBar {
self.files = files;
self
}
pub fn parts(mut self, parts: Vec<BarItem>) -> ProgressBar {
self.parts = parts;
self
Expand All @@ -29,12 +35,28 @@ impl ProgressBar {
impl Widget for ProgressBar {
fn render(self, area: Rect, buf: &mut Buffer) {
buf.set_style(area, Style::default());

let files = {
let format = CustomFormat::builder()
.grouping(Grouping::Standard)
.separator(" ")
.build()
.unwrap();

let mut buf = num_format::Buffer::new();
buf.write_formatted(&(self.files), &format);

format!("{} files ", buf.as_str())
};
let mut gauge_area = area;
if gauge_area.height < 1 || gauge_area.width < 3 || self.parts.is_empty() {
if gauge_area.height < 1
|| gauge_area.width < 3 + files.width() as u16
|| self.parts.is_empty()
{
return;
}
gauge_area.x += 1;
gauge_area.width -= 2;
gauge_area.x += 1 + files.width() as u16;
gauge_area.width -= 2 + files.width() as u16;

let parts = make_layout(&self.parts, gauge_area.width as usize);

Expand All @@ -54,6 +76,7 @@ impl Widget for ProgressBar {

x += width as u16;
}
buf.set_string(1, gauge_area.y, files, Style::default());
}
}

Expand Down
4 changes: 3 additions & 1 deletion cli/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,7 @@ fn create_progressbar(app: &FilesApp) -> ProgressBar {
});
}

ProgressBar::default().parts(items)
ProgressBar::default()
.parts(items)
.files(stats.files as u32)
}

0 comments on commit dbac5a1

Please sign in to comment.