diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-09-10 12:39:07 +0200 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-09-12 14:31:46 -0700 |
commit | 57a177e2f946390559a1f17787c5a15d23ac3393 (patch) | |
tree | a8069b927bdda75fbceb9e7a289d8338bb19fd8b /src/commands.rs | |
parent | 33918c32b8de4250c450f8d0b007019913c440a1 (diff) | |
download | nitrocli-57a177e2f946390559a1f17787c5a15d23ac3393.tar.gz nitrocli-57a177e2f946390559a1f17787c5a15d23ac3393.tar.bz2 |
Show progress bar in fill output
This patch uses the progressing crate to display a progress bar for the
fill command if the output is printed to a TTY.
Diffstat (limited to 'src/commands.rs')
-rw-r--r-- | src/commands.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/commands.rs b/src/commands.rs index 9af1853..ced976c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -23,6 +23,7 @@ use nitrokey::GetPasswordSafe; use crate::args; use crate::config; +use crate::output; use crate::pinentry; use crate::Context; @@ -482,20 +483,20 @@ pub fn fill(ctx: &mut Context<'_>) -> anyhow::Result<()> { device.fill_sd_card(&pin).context("Failed to fill SD card") })?; - let mut last_progress = 0; - loop { + let mut progress_bar = output::ProgressBar::new(); + progress_bar.draw(ctx)?; + + while !progress_bar.is_finished() { + thread::sleep(time::Duration::from_secs(1)); + let status = device .get_operation_status() .context("Failed to query operation status")?; match status { - nitrokey::OperationStatus::Ongoing(progress) => { - if last_progress != progress { - println!(ctx, "{}/100", progress)?; - } - last_progress = progress; - } - nitrokey::OperationStatus::Idle => break, + nitrokey::OperationStatus::Ongoing(progress) => progress_bar.update(progress)?, + nitrokey::OperationStatus::Idle => progress_bar.finish(), }; + progress_bar.draw(ctx)?; } Ok(()) |