use Action::Status on menu search

pull/6/head
dvkt 4 years ago
parent 56a63c5b34
commit a51e936d56

@ -207,10 +207,6 @@ impl Menu {
out.push_str("\r\n");
}
if self.searching {
out.push_str(&self.render_input());
}
// clear remainder of screen
let blank_line = " ".repeat(cols);
for _ in 0..rows - line_count - 1 {
@ -261,25 +257,14 @@ impl Menu {
/// User input field.
fn render_input(&self) -> String {
format!(
"{}Find:\x1b[0m {}{}{}",
cursor::Goto(1, self.rows() as u16),
self.input,
cursor::Show,
clear::UntilNewline,
)
format!("Find: {}{}", self.input, cursor::Show)
}
fn redraw_input(&self) -> Action {
if self.searching {
Action::Draw(self.render_input())
Action::Status(self.render_input())
} else {
Action::Draw(format!(
"{}{}{}",
cursor::Goto(1, self.rows() as u16),
clear::CurrentLine,
cursor::Hide
))
Action::Status(format!("{}", cursor::Hide))
}
}
@ -538,6 +523,7 @@ impl Menu {
}
}
/// Select and optionally scroll to a link.
fn action_select_link(&mut self, link: usize) -> Action {
if let Some(&pos) = self.links.get(link) {
let old_link = self.link;
@ -666,7 +652,7 @@ impl Menu {
}
Key::Char('f') | Key::Ctrl('f') | Key::Char('/') | Key::Char('i') | Key::Ctrl('i') => {
self.searching = true;
Action::Redraw
self.redraw_input()
}
Key::Char('w') | Key::Ctrl('w') => {
self.wide = !self.wide;

@ -66,9 +66,9 @@ impl UI {
}
pub fn draw(&mut self) {
let status = self.render_status();
if self.dirty {
let screen = self.render();
let status = self.render_status();
let mut out = self.out.borrow_mut();
write!(
out,
@ -81,7 +81,6 @@ impl UI {
out.flush();
self.dirty = false;
} else {
let status = self.render_status();
let mut out = self.out.borrow_mut();
out.write_all(status.as_ref());
out.flush();
@ -91,7 +90,12 @@ impl UI {
pub fn update(&mut self) {
let action = self.process_page_input();
if let Err(e) = self.process_action(action) {
self.set_status(format!("{}{}", color::Fg(color::LightRed), e));
self.set_status(format!(
"{}{}{}",
color::Fg(color::LightRed),
e,
termion::cursor::Hide
));
}
}
@ -252,7 +256,8 @@ impl UI {
fn render_status(&self) -> String {
format!(
"{}{}{}{}",
"{}{}{}{}{}",
termion::cursor::Hide,
termion::cursor::Goto(1, self.rows()),
termion::clear::CurrentLine,
self.status,

Loading…
Cancel
Save