From 159b9e409a51c629a47269482551982f3e771dd2 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Sun, 20 Jun 2021 15:02:58 +0000 Subject: [PATCH] Hightlight partial typed text --- src/view.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/view.rs b/src/view.rs index 61aacdc..e92cf95 100644 --- a/src/view.rs +++ b/src/view.rs @@ -92,7 +92,7 @@ impl<'a> View<'a> { } } - fn render(&self, stdout: &mut dyn Write) -> () { + fn render(&self, stdout: &mut dyn Write, typed_hint: &str) -> () { write!(stdout, "{}", cursor::Hide).unwrap(); for (index, line) in self.state.lines.iter().enumerate() { @@ -160,6 +160,18 @@ impl<'a> View<'a> { resetb = color::Bg(color::Reset), text = &text ); + + if hint.starts_with(typed_hint) { + print!( + "{goto}{background}{foregroud}{text}{resetf}{resetb}", + goto = cursor::Goto(final_position as u16 + 1, mat.y as u16 + 1), + foregroud = color::Fg(&*self.multi_foreground_color), + background = color::Bg(&*self.multi_background_color), + resetf = color::Fg(color::Reset), + resetb = color::Bg(color::Reset), + text = &typed_hint + ); + } } } @@ -180,7 +192,7 @@ impl<'a> View<'a> { .unwrap() .clone(); - self.render(stdout); + self.render(stdout, &typed_hint); loop { match stdin.keys().next() { @@ -207,6 +219,9 @@ impl<'a> View<'a> { Key::Right => { self.next(); } + Key::Backspace => { + typed_hint.pop(); + } Key::Char(ch) => { match ch { '\n' => match self.matches.iter().enumerate().find(|&h| h.0 == self.skip) { @@ -272,7 +287,7 @@ impl<'a> View<'a> { } } - self.render(stdout); + self.render(stdout, &typed_hint); } CaptureEvent::Exit