From 1ac99e16f8e71fd598dda27ac536c07b3338885f Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 21 Dec 2023 12:18:16 -0500 Subject: [PATCH] keyfork-prompt: add PromptManager::prompt_message --- keyfork-prompt/src/bin/test-basic-prompt.rs | 8 ++++---- keyfork-prompt/src/lib.rs | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/keyfork-prompt/src/bin/test-basic-prompt.rs b/keyfork-prompt/src/bin/test-basic-prompt.rs index 5fbc900..a95a749 100644 --- a/keyfork-prompt/src/bin/test-basic-prompt.rs +++ b/keyfork-prompt/src/bin/test-basic-prompt.rs @@ -4,9 +4,9 @@ use keyfork_prompt::*; pub fn main() -> Result<()> { let mut mgr = PromptManager::new(stdin(), stdout())?; - let line = mgr.prompt_input("Mnemonic: ")?; - dbg!(&line); - let line = mgr.prompt_passphrase("Passphrase: ")?; - dbg!(&line); + mgr.prompt_input("Mnemonic: ")?; + mgr.prompt_passphrase("Passphrase: ")?; + mgr.prompt_message("Please press enter.")?; + mgr.prompt_message("Please press space bar.")?; Ok(()) } diff --git a/keyfork-prompt/src/lib.rs b/keyfork-prompt/src/lib.rs index 34a5627..4001cc2 100644 --- a/keyfork-prompt/src/lib.rs +++ b/keyfork-prompt/src/lib.rs @@ -58,7 +58,6 @@ where } // TODO: return secrecy::Secret - // TODO: write a guard drop system for raw mode pub fn prompt_passphrase(&mut self, prompt: &str) -> Result { let mut terminal = AlternateScreen::new(&mut self.write)?; let mut terminal = RawMode::new(&mut terminal)?; @@ -84,4 +83,22 @@ where } Ok(passphrase) } + + pub fn prompt_message(&mut self, prompt: &str) -> Result<()> { + let mut terminal = AlternateScreen::new(&mut self.write)?; + let mut terminal = RawMode::new(&mut terminal)?; + terminal + .execute(terminal::Clear(terminal::ClearType::All))? + .execute(Print(prompt))?; + loop { + match read()? { + Event::Key(k) => match k.code { + KeyCode::Enter | KeyCode::Char(' ') => break, + _ => (), + }, + _ => (), + } + } + Ok(()) + } }