From b873ef4d5cd212023a80fabac01bd956e129ad4d Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 26 Dec 2023 18:08:52 -0500 Subject: [PATCH] keyfork-prompt: redraw screen on events for prompt_message --- keyfork-prompt/src/lib.rs | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/keyfork-prompt/src/lib.rs b/keyfork-prompt/src/lib.rs index 1fed38b..d994925 100644 --- a/keyfork-prompt/src/lib.rs +++ b/keyfork-prompt/src/lib.rs @@ -238,26 +238,27 @@ where let mut terminal = AlternateScreen::new(&mut self.write)?; let mut terminal = RawMode::new(&mut terminal)?; - terminal - .queue(terminal::Clear(terminal::ClearType::All))? - .queue(cursor::MoveTo(0, 0))?; - let mut lines = prompt.lines().peekable(); - while let Some(line) = lines.next() { - terminal.queue(Print(line))?; - if lines.peek().is_some() { - terminal - .queue(cursor::MoveDown(1))? - .queue(cursor::MoveToColumn(0))?; - } - } - terminal - .queue(cursor::DisableBlinking)? - .queue(cursor::MoveDown(1))? - .queue(cursor::MoveToColumn(0))? - .queue(PrintStyledContent(" OK ".negative()))? - .flush()?; - loop { + // TODO: split on word boundaries + terminal + .queue(terminal::Clear(terminal::ClearType::All))? + .queue(cursor::MoveTo(0, 0))?; + let mut lines = prompt.lines().peekable(); + while let Some(line) = lines.next() { + terminal.queue(Print(line))?; + if lines.peek().is_some() { + terminal + .queue(cursor::MoveDown(1))? + .queue(cursor::MoveToColumn(0))?; + } + } + terminal + .queue(cursor::DisableBlinking)? + .queue(cursor::MoveDown(1))? + .queue(cursor::MoveToColumn(0))? + .queue(PrintStyledContent(" OK ".negative()))? + .flush()?; + match read()? { Event::Key(k) => match k.code { KeyCode::Enter | KeyCode::Char(' ') => break, @@ -265,6 +266,8 @@ where }, _ => (), } + + } terminal.queue(cursor::EnableBlinking)?.flush()?; Ok(())