Skip to content

Commit

Permalink
Leave incomplete progress bars when exitting early
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Sep 25, 2022
1 parent 04831e4 commit 0727373
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
* Leave incomplete progress bars when exitting early with _ctrl c_ instead of clearing them.

# v0.4.2
* Update _indicatif_ dependency to `0.17`.

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/command/auto_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};
use clap::Parser;
use console::style;
use indicatif::{ProgressBar, ProgressStyle};
use indicatif::{ProgressBar, ProgressFinish, ProgressStyle};
use std::time::Duration;

/// Automatically determine the best crf to deliver the min-vmaf and use it to encode a video.
Expand Down Expand Up @@ -39,11 +39,13 @@ pub async fn auto_encode(Args { mut search, encode }: Args) -> anyhow::Result<()
.output
.unwrap_or_else(|| default_output_from(&search.args));

let bar = ProgressBar::new(12).with_style(
ProgressStyle::default_bar()
.template(SPINNER_RUNNING)?
.progress_chars(PROGRESS_CHARS),
);
let bar = ProgressBar::new(12)
.with_style(
ProgressStyle::default_bar()
.template(SPINNER_RUNNING)?
.progress_chars(PROGRESS_CHARS),
)
.with_finish(ProgressFinish::Abandon);

bar.set_prefix("Searching");
if defaulting_output {
Expand Down Expand Up @@ -95,7 +97,7 @@ pub async fn auto_encode(Args { mut search, encode }: Args) -> anyhow::Result<()
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {prefix} {elapsed_precise:.bold} {wide_bar:.cyan/blue} ({msg}eta {eta})")?
.progress_chars(PROGRESS_CHARS)
);
).with_finish(ProgressFinish::Abandon);
bar.set_prefix("Encoding ");
bar.enable_steady_tick(Duration::from_millis(100));

Expand Down
4 changes: 2 additions & 2 deletions src/command/crf_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use clap::Parser;
use console::style;
use err::ensure_other;
use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressStyle};
use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressFinish, ProgressStyle};
use std::time::Duration;

const BAR_LEN: u64 = 1000;
Expand Down Expand Up @@ -59,7 +59,7 @@ pub async fn crf_search(args: Args) -> anyhow::Result<()> {
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {elapsed_precise:.bold} {wide_bar:.cyan/blue} ({msg}eta {eta})")?
.progress_chars(PROGRESS_CHARS)
);
).with_finish(ProgressFinish::Abandon);

let best = run(&args, bar.clone()).await;
bar.finish();
Expand Down
4 changes: 2 additions & 2 deletions src/command/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use clap::Parser;
use console::style;
use indicatif::{HumanBytes, ProgressBar, ProgressStyle};
use indicatif::{HumanBytes, ProgressBar, ProgressFinish, ProgressStyle};
use std::{path::PathBuf, time::Duration};
use tokio::fs;
use tokio_stream::StreamExt;
Expand All @@ -35,7 +35,7 @@ pub async fn encode(args: Args) -> anyhow::Result<()> {
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {elapsed_precise:.bold} {wide_bar:.cyan/blue} ({msg}eta {eta})")?
.progress_chars(PROGRESS_CHARS)
);
).with_finish(ProgressFinish::Abandon);
bar.enable_steady_tick(Duration::from_millis(100));

run(args, &bar).await
Expand Down
4 changes: 2 additions & 2 deletions src/command/sample_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
use anyhow::ensure;
use clap::Parser;
use console::style;
use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressStyle};
use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressFinish, ProgressStyle};
use std::{
path::PathBuf,
sync::Arc,
Expand Down Expand Up @@ -62,7 +62,7 @@ pub async fn sample_encode(args: Args) -> anyhow::Result<()> {
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {elapsed_precise:.bold} {prefix} {wide_bar:.cyan/blue} ({msg:13} eta {eta})")?
.progress_chars(PROGRESS_CHARS)
);
).with_finish(ProgressFinish::Abandon);
bar.enable_steady_tick(Duration::from_millis(100));

run(args, bar).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/command/vmaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
vmaf::VmafOut,
};
use clap::Parser;
use indicatif::{ProgressBar, ProgressStyle};
use indicatif::{ProgressBar, ProgressFinish, ProgressStyle};
use std::{path::PathBuf, time::Duration};
use tokio_stream::StreamExt;

Expand Down Expand Up @@ -45,7 +45,7 @@ pub async fn vmaf(
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {elapsed_precise:.bold} {wide_bar:.cyan/blue} ({msg}eta {eta})")?
.progress_chars(PROGRESS_CHARS)
);
).with_finish(ProgressFinish::Abandon);
bar.enable_steady_tick(Duration::from_millis(100));
bar.set_message("vmaf running, ");

Expand Down

0 comments on commit 0727373

Please sign in to comment.