Skip to content

Commit c416152

Browse files
committed
Automatically close the TUI when there is no progress anymore.
1 parent 60eaea0 commit c416152

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

Diff for: Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ git-features = { version = "0.1.0", path = "git-features" }
4040

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

Diff for: git-features/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ fastsha1 = { package = "sha-1", version = "0.9.1", optional = true }
3232

3333
# progress
3434
log = { version = "0.4.8", optional = true }
35-
prodash = { version = "4.0.5", optional = true, default-features = false }
35+
prodash = { version = "4.1.0", optional = true, default-features = false }

Diff for: src/plumbing/pretty.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn init_progress(
4242
verbose: bool,
4343
progress: bool,
4444
) -> (
45-
Option<std::thread::JoinHandle<()>>,
45+
Option<JoinThreadOnDrop>,
4646
Option<progress::Either<progress::Log, prodash::tree::Item>>,
4747
) {
4848
super::init_env_logger(verbose);
@@ -63,13 +63,19 @@ fn init_progress(
6363
.expect("tui to come up without io error");
6464
let handle = std::thread::spawn(move || smol::run(render_tui));
6565

66-
(Some(handle), Some(progress::Either::Right(sub_progress)))
66+
(
67+
Some(JoinThreadOnDrop(Some(handle))),
68+
Some(progress::Either::Right(sub_progress)),
69+
)
6770
}
6871
}
6972
}
7073

71-
fn join<T>(handle: Option<std::thread::JoinHandle<T>>) -> Option<T> {
72-
handle.and_then(|h| h.join().ok())
74+
struct JoinThreadOnDrop(Option<std::thread::JoinHandle<()>>);
75+
impl Drop for JoinThreadOnDrop {
76+
fn drop(&mut self) {
77+
self.0.take().and_then(|handle| handle.join().ok());
78+
}
7379
}
7480

7581
pub fn main() -> Result<()> {
@@ -81,10 +87,8 @@ pub fn main() -> Result<()> {
8187
verbose,
8288
progress,
8389
} => {
84-
let (handle, progress) = init_progress("verify-pack", verbose, progress);
85-
let res = core::verify_pack_or_pack_index(path, progress, stdout(), stderr());
86-
join(handle);
87-
res
90+
let (_keep, progress) = init_progress("verify-pack", verbose, progress);
91+
core::verify_pack_or_pack_index(path, progress, stdout(), stderr())
8892
}
8993
}?;
9094
Ok(())

0 commit comments

Comments
 (0)