Skip to content

Commit 8757ec9

Browse files
committed
progress indicator skeleton
1 parent 5e4da13 commit 8757ec9

File tree

13 files changed

+590
-292
lines changed

13 files changed

+590
-292
lines changed

Cargo.lock

Lines changed: 40 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@ ahash = "0.8.6"
3434
ansi_term = "0.12.1"
3535
anyhow = "1.0.75"
3636
chrono = { version = "0.4.24", default-features = false, features = ["clock", "std"] }
37-
clap = { version = "4.4.10", features = ["derive"] }
37+
clap = { version = "4.5.4", features = ["derive"] }
3838
clap_complete = "4.1.1"
3939
config = { version = "0.14.0", default-features = false, features = ["toml"] }
40-
crossterm = "0.26.1"
40+
crossterm = "0.27.0"
4141
ctrlc = "3.4.0"
4242
dirs = "5.0"
4343
errno = "0.3.1"
4444
filesize = "0.2.0"
4545
ignore = "0.4.2"
4646
indextree = "4.6.0"
47-
log = { version = "0.4.20", features = ["std"] }
4847
lscolors = { version = "0.13.0", features = ["ansi_term"] }
49-
once_cell = "1.17.0"
48+
once_cell = "1.19.0"
5049
regex = "1.7.3"
5150
terminal_size = "0.2.6"
5251
thiserror = "1.0.40"

rustfmt.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/disk/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ impl Usage {
119119
std::fs::read_to_string(data.path()).map(|data| data.split_whitespace().count())?;
120120

121121
let word_count = u64::try_from(word_count).map_or_else(
122-
|e| {
123-
log::warn!("Usage::init_word_count {e}");
124-
Self::WordCount(word_count as u64)
125-
},
122+
|_| Self::WordCount(word_count as u64),
126123
Self::WordCount,
127124
);
128125

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

146143
let line_count = u64::try_from(line_count).map_or_else(
147-
|e| {
148-
log::warn!("Usage::init_line_count {e}");
149-
Self::WordCount(line_count as u64)
150-
},
144+
|_| Self::WordCount(line_count as u64),
151145
Self::LineCount,
152146
);
153147

src/file/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ pub struct File {
4646
unix_attrs: unix::Attrs,
4747
}
4848

49+
// For keeping track of the count of file-types while loading from disk.
50+
#[derive(Default)]
51+
pub struct Accumulator {
52+
num_file: usize,
53+
num_dir: usize,
54+
num_link: usize,
55+
}
56+
4957
/// [`Display`] implementation concerned with human-readable presentation of the file-name.
5058
pub struct DisplayName<'a> {
5159
file: &'a File,
@@ -246,6 +254,26 @@ impl Deref for File {
246254
}
247255
}
248256

257+
impl Accumulator {
258+
pub fn total(&self) -> usize {
259+
self.num_dir + self.num_file + self.num_link
260+
}
261+
262+
pub fn increment(&mut self, ft: Option<fs::FileType>) {
263+
let Some(file_type) = ft else {
264+
return
265+
};
266+
267+
if file_type.is_file() {
268+
self.num_file += 1;
269+
} else if file_type.is_dir() {
270+
self.num_dir += 1;
271+
} else if file_type.is_symlink() {
272+
self.num_link += 1;
273+
}
274+
}
275+
}
276+
249277
impl Display for DisplayName<'_> {
250278
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
251279
let file_name = self.file.file_name().to_string_lossy();

0 commit comments

Comments
 (0)