-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve UX by adding console output (#24)
* feat: Improve UX by adding console output * Print to stderr * Add spinner for unpacking * Revert to no spinner * Fix * Fix progress bar for unpacking * Remove total length from bar * Fix bug * Fix bug * Remove install progress reporter again
- Loading branch information
Showing
6 changed files
with
89 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::{path::Path, time::Duration}; | ||
|
||
use indicatif::{ProgressBar, ProgressStyle}; | ||
|
||
/// Progress reporter that wraps a progress bar with default styles. | ||
pub struct ProgressReporter { | ||
pub pb: ProgressBar, | ||
} | ||
|
||
impl ProgressReporter { | ||
pub fn new(length: u64) -> Self { | ||
let pb = ProgressBar::new(length).with_style( | ||
ProgressStyle::with_template("[{elapsed_precise}] {bar:40.cyan/blue} {msg}") | ||
.expect("could not set progress style") | ||
.progress_chars("##-"), | ||
); | ||
pb.enable_steady_tick(Duration::from_millis(500)); | ||
Self { pb } | ||
} | ||
} | ||
|
||
/// Get the size of a file or directory in bytes. | ||
pub fn get_size<P: AsRef<Path>>(path: P) -> std::io::Result<u64> { | ||
let metadata = std::fs::metadata(&path)?; | ||
let mut size = metadata.len(); | ||
if metadata.is_dir() { | ||
for entry in std::fs::read_dir(&path)? { | ||
size += get_size(entry?.path())?; | ||
} | ||
} | ||
Ok(size) | ||
} |