-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(import): add a progress meter for getting an ETA
- Loading branch information
Showing
4 changed files
with
35 additions
and
23 deletions.
There are no files selected for viewing
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,26 @@ | ||
use indicatif::MultiProgress; | ||
use indicatif_log_bridge::LogWrapper; | ||
use std::io::IsTerminal; | ||
use walker_common::progress::indicatif::MultiIndicatif; | ||
use walker_common::progress::{NoProgress, Progress}; | ||
|
||
/// Set up the env_logger and attach a progress interface if we are running on a terminal. | ||
pub(crate) fn init_log_and_progress() -> Progress { | ||
let mut builder = env_logger::builder(); | ||
let logger = builder.build(); | ||
|
||
match std::io::stdin().is_terminal() { | ||
true => { | ||
let max_level = logger.filter(); | ||
let multi = MultiProgress::new(); | ||
|
||
let log = LogWrapper::new(multi.clone(), logger); | ||
// NOTE: LogWrapper::try_init is buggy and messes up the log levels | ||
log::set_boxed_logger(Box::new(log)).unwrap(); | ||
log::set_max_level(max_level); | ||
|
||
Progress::new(MultiIndicatif(multi)) | ||
} | ||
false => Progress::new(NoProgress), | ||
} | ||
} |
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