Skip to content

Commit

Permalink
Hightlight partial typed text
Browse files Browse the repository at this point in the history
  • Loading branch information
fcsonline committed Jun 20, 2021
1 parent 7962baa commit 159b9e4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
);
}
}
}

Expand All @@ -180,7 +192,7 @@ impl<'a> View<'a> {
.unwrap()
.clone();

self.render(stdout);
self.render(stdout, &typed_hint);

loop {
match stdin.keys().next() {
Expand All @@ -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) {
Expand Down Expand Up @@ -272,7 +287,7 @@ impl<'a> View<'a> {
}
}

self.render(stdout);
self.render(stdout, &typed_hint);
}

CaptureEvent::Exit
Expand Down

0 comments on commit 159b9e4

Please sign in to comment.