Skip to content

Commit

Permalink
Print secret message to tty, normal message otherwise
Browse files Browse the repository at this point in the history
Port 586ff3e547feddb782dde3d8dde7e45842df92ba from FuelLabs/fuel-core#1426

Context: FuelLabs/fuel-core#1426 (comment)
  • Loading branch information
cr-fuel committed Oct 26, 2023
1 parent c7561c6 commit 91025bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 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 forc-plugins/forc-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository.workspace = true
[dependencies]
anyhow = "1.0.75"
async-trait = "0.1.58"
atty = "0.2.14"
clap = { version = "3", features = ["derive", "env"] }
forc-tracing = { version = "0.46.0", path = "../../forc-tracing" }
fuel-core-types = { version = "0.20.5" }
Expand Down
21 changes: 13 additions & 8 deletions forc-plugins/forc-crypto/src/keygen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use atty::Stream;
use clap::ValueEnum;
use std::io::{Read, Write};
use std::io::{stdin, stdout, Read, Write};
use termion::screen::IntoAlternateScreen;

pub mod new_key;
pub mod parse_secret;
Expand All @@ -16,18 +18,21 @@ pub enum KeyType {

fn wait_for_keypress() {
let mut single_key = [0u8];
std::io::stdin().read_exact(&mut single_key).unwrap();
stdin().read_exact(&mut single_key).unwrap();
}

pub(crate) fn display_string_discreetly(
discreet_string: &str,
continue_message: &str,
) -> anyhow::Result<()> {
use termion::screen::IntoAlternateScreen;
let mut screen = std::io::stdout().into_alternate_screen()?;
writeln!(screen, "{discreet_string}")?;
screen.flush()?;
println!("{continue_message}");
wait_for_keypress();
if atty::is(Stream::Stdout) {
let mut screen = stdout().into_alternate_screen()?;
writeln!(screen, "{discreet_string}")?;
screen.flush()?;
println!("{continue_message}");
wait_for_keypress();
} else {
print!("{discreet_string}");
}
Ok(())
}

0 comments on commit 91025bf

Please sign in to comment.