Hightlight partial typed text

This commit is contained in:
Ferran Basora 2021-06-20 15:02:58 +00:00
parent 7962baac56
commit 159b9e409a

View File

@ -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(); write!(stdout, "{}", cursor::Hide).unwrap();
for (index, line) in self.state.lines.iter().enumerate() { for (index, line) in self.state.lines.iter().enumerate() {
@ -160,6 +160,18 @@ impl<'a> View<'a> {
resetb = color::Bg(color::Reset), resetb = color::Bg(color::Reset),
text = &text 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() .unwrap()
.clone(); .clone();
self.render(stdout); self.render(stdout, &typed_hint);
loop { loop {
match stdin.keys().next() { match stdin.keys().next() {
@ -207,6 +219,9 @@ impl<'a> View<'a> {
Key::Right => { Key::Right => {
self.next(); self.next();
} }
Key::Backspace => {
typed_hint.pop();
}
Key::Char(ch) => { Key::Char(ch) => {
match ch { match ch {
'\n' => match self.matches.iter().enumerate().find(|&h| h.0 == self.skip) { '\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 CaptureEvent::Exit