Skip to content

Commit

Permalink
progress indicator skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
solidiquis committed May 19, 2024
1 parent 5e4da13 commit 8757ec9
Show file tree
Hide file tree
Showing 13 changed files with 590 additions and 292 deletions.
68 changes: 40 additions & 28 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@ ahash = "0.8.6"
ansi_term = "0.12.1"
anyhow = "1.0.75"
chrono = { version = "0.4.24", default-features = false, features = ["clock", "std"] }
clap = { version = "4.4.10", features = ["derive"] }
clap = { version = "4.5.4", features = ["derive"] }
clap_complete = "4.1.1"
config = { version = "0.14.0", default-features = false, features = ["toml"] }
crossterm = "0.26.1"
crossterm = "0.27.0"
ctrlc = "3.4.0"
dirs = "5.0"
errno = "0.3.1"
filesize = "0.2.0"
ignore = "0.4.2"
indextree = "4.6.0"
log = { version = "0.4.20", features = ["std"] }
lscolors = { version = "0.13.0", features = ["ansi_term"] }
once_cell = "1.17.0"
once_cell = "1.19.0"
regex = "1.7.3"
terminal_size = "0.2.6"
thiserror = "1.0.40"
Expand Down
1 change: 0 additions & 1 deletion rustfmt.toml

This file was deleted.

10 changes: 2 additions & 8 deletions src/disk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ impl Usage {
std::fs::read_to_string(data.path()).map(|data| data.split_whitespace().count())?;

let word_count = u64::try_from(word_count).map_or_else(
|e| {
log::warn!("Usage::init_word_count {e}");
Self::WordCount(word_count as u64)
},
|_| Self::WordCount(word_count as u64),
Self::WordCount,
);

Expand All @@ -144,10 +141,7 @@ impl Usage {
let line_count = fs::read_to_string(data.path()).map(|data| data.lines().count())?;

let line_count = u64::try_from(line_count).map_or_else(
|e| {
log::warn!("Usage::init_line_count {e}");
Self::WordCount(line_count as u64)
},
|_| Self::WordCount(line_count as u64),
Self::LineCount,
);

Expand Down
28 changes: 28 additions & 0 deletions src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ pub struct File {
unix_attrs: unix::Attrs,
}

// For keeping track of the count of file-types while loading from disk.
#[derive(Default)]
pub struct Accumulator {
num_file: usize,
num_dir: usize,
num_link: usize,
}

/// [`Display`] implementation concerned with human-readable presentation of the file-name.
pub struct DisplayName<'a> {
file: &'a File,
Expand Down Expand Up @@ -246,6 +254,26 @@ impl Deref for File {
}
}

impl Accumulator {
pub fn total(&self) -> usize {
self.num_dir + self.num_file + self.num_link
}

pub fn increment(&mut self, ft: Option<fs::FileType>) {
let Some(file_type) = ft else {
return
};

if file_type.is_file() {
self.num_file += 1;
} else if file_type.is_dir() {
self.num_dir += 1;
} else if file_type.is_symlink() {
self.num_link += 1;
}
}
}

impl Display for DisplayName<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let file_name = self.file.file_name().to_string_lossy();
Expand Down
Loading

0 comments on commit 8757ec9

Please sign in to comment.