keyfork-prompt: add PromptManager::prompt_message

This commit is contained in:
Ryan Heywood 2023-12-21 12:18:16 -05:00
parent 0ea49109d1
commit 1ac99e16f8
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
2 changed files with 22 additions and 5 deletions

View File

@ -4,9 +4,9 @@ use keyfork_prompt::*;
pub fn main() -> Result<()> { pub fn main() -> Result<()> {
let mut mgr = PromptManager::new(stdin(), stdout())?; let mut mgr = PromptManager::new(stdin(), stdout())?;
let line = mgr.prompt_input("Mnemonic: ")?; mgr.prompt_input("Mnemonic: ")?;
dbg!(&line); mgr.prompt_passphrase("Passphrase: ")?;
let line = mgr.prompt_passphrase("Passphrase: ")?; mgr.prompt_message("Please press enter.")?;
dbg!(&line); mgr.prompt_message("Please press space bar.")?;
Ok(()) Ok(())
} }

View File

@ -58,7 +58,6 @@ where
} }
// TODO: return secrecy::Secret<String> // TODO: return secrecy::Secret<String>
// TODO: write a guard drop system for raw mode
pub fn prompt_passphrase(&mut self, prompt: &str) -> Result<String> { pub fn prompt_passphrase(&mut self, prompt: &str) -> Result<String> {
let mut terminal = AlternateScreen::new(&mut self.write)?; let mut terminal = AlternateScreen::new(&mut self.write)?;
let mut terminal = RawMode::new(&mut terminal)?; let mut terminal = RawMode::new(&mut terminal)?;
@ -84,4 +83,22 @@ where
} }
Ok(passphrase) 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(())
}
} }