aboutsummaryrefslogtreecommitdiff
path: root/src/commands.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-10 12:39:07 +0200
committerDaniel Mueller <deso@posteo.net>2021-01-10 21:05:44 -0800
commite085dcda752f7a5007e35c2baecbf094d888faa0 (patch)
tree45a1000cd8f69d6f02dae64bc1f17d48b4a84176 /src/commands.rs
parent763219bc4331331351b4180d4775432e9e11f8b2 (diff)
downloadnitrocli-e085dcda752f7a5007e35c2baecbf094d888faa0.tar.gz
nitrocli-e085dcda752f7a5007e35c2baecbf094d888faa0.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.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/commands.rs b/src/commands.rs
index cf3b94f..7b48bb2 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(())