Skip to content

Commit

Permalink
fix: hidden cursor when ctrl-c gets invoked (#57)
Browse files Browse the repository at this point in the history
If a user pressed ctrl-c/ctrl-d during the questioning process, the
cursor would be hidden after the process gets terminated. A custom
callback has been registered that restores the cursor if one of the
signals gets send.

Fixes #40
  • Loading branch information
SirWindfield authored Mar 21, 2021
1 parent c18944d commit 37bdac3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
39 changes: 34 additions & 5 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ anyhow = "1.0.39"
cargo_toml = "0.8.1"
clap = "3.0.0-beta.2"
console = "0.14.1"
ctrlc = { version = "3.1.8", features = ["termination"] }
dialoguer = "0.8.0"
edit = "0.1.3"
git2 = { version = "0.13.17", features = ["vendored-openssl"] }
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ fn main() {
if !app.repo_path.exists() || get_repository(app.repo_path.as_path()).is_err() {
eprintln!("Invalid path to repository: {}", app.repo_path.display());
} else {
// When terminating the CLI during the dialoguer phase, the cursor will be
// hidden. The callback here makes sure that the cursor is visible in these
// cases.
let _ = ctrlc::set_handler(move || {
let term = dialoguer::console::Term::stderr();
let _ = term.show_cursor();
std::process::exit(1);
});

run(app);
}
}

0 comments on commit 37bdac3

Please sign in to comment.