diff --git a/keyfork-prompt/src/bin/test-basic-prompt.rs b/keyfork-prompt/src/bin/test-basic-prompt.rs index a95a749..5361622 100644 --- a/keyfork-prompt/src/bin/test-basic-prompt.rs +++ b/keyfork-prompt/src/bin/test-basic-prompt.rs @@ -5,8 +5,8 @@ use keyfork_prompt::*; pub fn main() -> Result<()> { let mut mgr = PromptManager::new(stdin(), stdout())?; mgr.prompt_input("Mnemonic: ")?; - mgr.prompt_passphrase("Passphrase: ")?; mgr.prompt_message("Please press enter.")?; + mgr.prompt_passphrase("Passphrase: ")?; mgr.prompt_message("Please press space bar.")?; Ok(()) } diff --git a/keyfork-prompt/src/lib.rs b/keyfork-prompt/src/lib.rs index 4001cc2..9d30181 100644 --- a/keyfork-prompt/src/lib.rs +++ b/keyfork-prompt/src/lib.rs @@ -5,10 +5,11 @@ use std::{ use crossterm::{ event::{read, Event, KeyCode}, - style::Print, + style::{Print, PrintStyledContent, Stylize}, terminal, + cursor, tty::IsTty, - ExecutableCommand, + QueueableCommand, }; mod alternate_screen; @@ -50,8 +51,9 @@ where pub fn prompt_input(&mut self, prompt: &str) -> Result { let mut terminal = AlternateScreen::new(&mut self.write)?; terminal - .execute(terminal::Clear(terminal::ClearType::All))? - .execute(Print(prompt))?; + .queue(terminal::Clear(terminal::ClearType::All))? + .queue(Print(prompt))? + .flush()?; let mut line = String::new(); self.read.read_line(&mut line)?; Ok(line) @@ -62,8 +64,9 @@ where 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))?; + .queue(terminal::Clear(terminal::ClearType::All))? + .queue(Print(prompt))? + .flush()?; let mut passphrase = String::new(); loop { match read()? { @@ -73,7 +76,7 @@ where break; } KeyCode::Char(c) => { - terminal.execute(Print("*"))?; + terminal.queue(Print("*"))?.flush()?; passphrase.push(c); } _ => (), @@ -88,8 +91,13 @@ where 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))?; + .queue(terminal::Clear(terminal::ClearType::All))? + .queue(Print(prompt))? + .queue(cursor::DisableBlinking)? + .queue(cursor::MoveDown(1))? + .queue(cursor::MoveToColumn(0))? + .queue(PrintStyledContent(" OK ".negative()))? + .flush()?; loop { match read()? { Event::Key(k) => match k.code { @@ -99,6 +107,7 @@ where _ => (), } } + terminal.queue(cursor::EnableBlinking)?.flush()?; Ok(()) } }