From a51e936d567d5ec931528d3317281d7bea6a9101 Mon Sep 17 00:00:00 2001 From: dvkt Date: Thu, 2 Jan 2020 12:37:18 -0800 Subject: [PATCH] use Action::Status on menu search --- src/menu.rs | 24 +++++------------------- src/ui.rs | 13 +++++++++---- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/menu.rs b/src/menu.rs index 6999950..b31759f 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -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; diff --git a/src/ui.rs b/src/ui.rs index b62749f..073ba7a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -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,