Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve ctrl-c handling to deal with blocking threads and terminal shenanigans #2950

Merged
merged 10 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

### Fixed

- [#2950](https://github.com/ChainSafe/forest/pull/2950): Fix cases where ctrl-c
would be ignored.

## Forest v0.8.2 "The Way"

### Added
Expand Down
35 changes: 11 additions & 24 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ quickcheck_macros = "1"
rand = "0.8"
rayon = "1.5"
regex = "1.8"
rpassword = "7.2"
serde = { version = "1.0", default-features = false }
serde_ipld_dagcbor = "0.2"
serde_json = "1.0"
Expand Down
1 change: 0 additions & 1 deletion forest/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ log.workspace = true
multibase.workspace = true
nom = "7.1.3"
num.workspace = true
rpassword.workspace = true
rustyline = "10.1.1"
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down
11 changes: 8 additions & 3 deletions forest/cli/src/cli/wallet_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
use anyhow::Context;
use base64::{prelude::BASE64_STANDARD, Engine};
use clap::{arg, Subcommand};
use dialoguer::{theme::ColorfulTheme, Password};
use forest_json::{
address::json::AddressJson,
signature::json::{signature_type::SignatureTypeJson, SignatureJson},
Expand All @@ -22,7 +23,6 @@ use forest_shim::{
};
use forest_utils::io::read_file_to_string;
use num::BigInt;
use rpassword::read_password;

use super::{handle_rpc_err, Config};
use crate::humantoken::TokenAmountPretty as _;
Expand Down Expand Up @@ -150,8 +150,13 @@ impl WalletCommands {
let key = match path {
Some(path) => read_file_to_string(&PathBuf::from(path))?,
_ => {
println!("Enter the private key: ");
read_password()?
tokio::task::spawn_blocking(|| {
Password::with_theme(&ColorfulTheme::default())
.allow_empty_password(true)
.with_prompt("Enter the private key")
.interact()
})
.await??
}
};

Expand Down
2 changes: 0 additions & 2 deletions forest/daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ name = "forest"
path = "src/main.rs"

[dependencies]
anes.workspace = true
anyhow.workspace = true
atty.workspace = true
cfg-if.workspace = true
Expand Down Expand Up @@ -46,7 +45,6 @@ fvm_ipld_blockstore.workspace = true
lazy_static.workspace = true
log.workspace = true
raw_sync = "0.1"
rpassword.workspace = true
serde_json.workspace = true
shared_memory = "0.12"
tempfile.workspace = true
Expand Down
16 changes: 0 additions & 16 deletions forest/daemon/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// Copyright 2019-2023 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use std::io::Write;

use anes::execute;
use clap::Parser;
use forest_cli_shared::cli::{CliOpts, HELP_MESSAGE};
use forest_utils::version::FOREST_VERSION_STRING;
use tokio::{signal, task};

/// CLI structure generated when interacting with Forest binary
#[derive(Parser)]
Expand All @@ -18,15 +14,3 @@ pub struct Cli {
pub opts: CliOpts,
pub cmd: Option<String>,
}

pub fn set_sigint_handler() {
task::spawn(async {
let _ = signal::ctrl_c().await;

// the cursor can go missing if we hit ctrl-c during a prompt, so we always
// restore it
let mut stdout = std::io::stdout();
#[allow(clippy::question_mark)]
execute!(&mut stdout, anes::ShowCursor).unwrap();
});
}
Loading