Skip to content

Commit

Permalink
Automatically close the TUI when there is no progress anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 1, 2020
1 parent 60eaea0 commit c416152
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ git-features = { version = "0.1.0", path = "git-features" }

structopt = { version = "0.3.14", optional = true }
argh = { version = "0.1.3", optional = true }
prodash = { version = "4.0.5", optional = true, default-features = false }
prodash = { version = "4.1.0", optional = true, default-features = false }
smol = { version = "0.1.18", optional = true }
env_logger = { version = "0.7.1", optional = true, default-features = false, features = ["humantime", "termcolor", "atty"] }

Expand Down
2 changes: 1 addition & 1 deletion git-features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ fastsha1 = { package = "sha-1", version = "0.9.1", optional = true }

# progress
log = { version = "0.4.8", optional = true }
prodash = { version = "4.0.5", optional = true, default-features = false }
prodash = { version = "4.1.0", optional = true, default-features = false }
20 changes: 12 additions & 8 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn init_progress(
verbose: bool,
progress: bool,
) -> (
Option<std::thread::JoinHandle<()>>,
Option<JoinThreadOnDrop>,
Option<progress::Either<progress::Log, prodash::tree::Item>>,
) {
super::init_env_logger(verbose);
Expand All @@ -63,13 +63,19 @@ fn init_progress(
.expect("tui to come up without io error");
let handle = std::thread::spawn(move || smol::run(render_tui));

(Some(handle), Some(progress::Either::Right(sub_progress)))
(
Some(JoinThreadOnDrop(Some(handle))),
Some(progress::Either::Right(sub_progress)),
)
}
}
}

fn join<T>(handle: Option<std::thread::JoinHandle<T>>) -> Option<T> {
handle.and_then(|h| h.join().ok())
struct JoinThreadOnDrop(Option<std::thread::JoinHandle<()>>);
impl Drop for JoinThreadOnDrop {
fn drop(&mut self) {
self.0.take().and_then(|handle| handle.join().ok());
}
}

pub fn main() -> Result<()> {
Expand All @@ -81,10 +87,8 @@ pub fn main() -> Result<()> {
verbose,
progress,
} => {
let (handle, progress) = init_progress("verify-pack", verbose, progress);
let res = core::verify_pack_or_pack_index(path, progress, stdout(), stderr());
join(handle);
res
let (_keep, progress) = init_progress("verify-pack", verbose, progress);
core::verify_pack_or_pack_index(path, progress, stdout(), stderr())
}
}?;
Ok(())
Expand Down

0 comments on commit c416152

Please sign in to comment.