From 75a38fa38b65c075f34233f4745eb6d1d7405a39 Mon Sep 17 00:00:00 2001 From: mo8it Date: Sun, 1 Sep 2024 20:44:19 +0200 Subject: [PATCH] Add search to the help footer --- src/list/state.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/list/state.rs b/src/list/state.rs index bc1ac72..49b6d5d 100644 --- a/src/list/state.rs +++ b/src/list/state.rs @@ -44,7 +44,6 @@ pub struct ListState<'a> { term_width: u16, term_height: u16, separator_line: Vec, - narrow_term: bool, show_footer: bool, } @@ -78,7 +77,6 @@ impl<'a> ListState<'a> { term_width: 0, term_height: 0, separator_line: Vec::new(), - narrow_term: false, show_footer: true, }; @@ -96,13 +94,9 @@ impl<'a> ListState<'a> { return; } - let wide_help_footer_width = 95; - // The help footer is shorter when nothing is selected. - self.narrow_term = width < wide_help_footer_width && self.scroll_state.selected().is_some(); - let header_height = 1; - // 2 separator, 1 progress bar, 1-2 footer message. - let footer_height = 4 + u16::from(self.narrow_term); + // 2 separators, 1 progress bar, 2 footer message lines. + let footer_height = 5; self.show_footer = height > header_height + footer_height; if self.show_footer { @@ -227,14 +221,10 @@ impl<'a> ListState<'a> { // Help footer message if self.scroll_state.selected().is_some() { writer.write_str("↓/j ↑/k home/g end/G | ontinue at | eset exercise")?; - if self.narrow_term { - next_ln(stdout)?; - writer = MaxLenWriter::new(stdout, self.term_width as usize); + next_ln(stdout)?; + writer = MaxLenWriter::new(stdout, self.term_width as usize); - writer.write_ascii(b"filter ")?; - } else { - writer.write_ascii(b" | filter ")?; - } + writer.write_ascii(b"earch | filter ")?; } else { // Nothing selected (and nothing shown), so only display filter and quit. writer.write_ascii(b"filter ")?; @@ -263,17 +253,14 @@ impl<'a> ListState<'a> { } writer.write_ascii(b" | uit list")?; - next_ln(stdout)?; } else { writer.stdout.queue(SetForegroundColor(Color::Magenta))?; writer.write_str(&self.message)?; stdout.queue(ResetColor)?; next_ln(stdout)?; - - if self.narrow_term { - next_ln(stdout)?; - } } + + next_ln(stdout)?; } stdout.queue(EndSynchronizedUpdate)?.flush()