diff options
author | Gleb Davydov <23462908+Mifom@users.noreply.github.com> | 2021-10-15 18:23:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 17:23:57 +0200 |
commit | 899168e1ce0e17f1572ce36783bd67c0fb963ad1 (patch) | |
tree | 5104e15e783f0f6572f7dcfe294db7b619f2429a /src/ui | |
parent | 153c79a82890ca58c85e8ff0a1bda8c6cb7de349 (diff) |
Add highlighting for matches in fuzzy finder (#947)
closes #893
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/scrolllist.rs | 27 | ||||
-rw-r--r-- | src/ui/style.rs | 3 |
2 files changed, 18 insertions, 12 deletions
diff --git a/src/ui/scrolllist.rs b/src/ui/scrolllist.rs index adc04bb3..e8a0e527 100644 --- a/src/ui/scrolllist.rs +++ b/src/ui/scrolllist.rs @@ -5,15 +5,16 @@ use tui::{ buffer::Buffer, layout::Rect, style::Style, - text::Span, + text::{Span, Text}, widgets::{Block, Borders, List, ListItem, Widget}, Frame, }; /// -struct ScrollableList<'b, L> +struct ScrollableList<'b, L, S> where - L: Iterator<Item = Span<'b>>, + S: Into<Text<'b>>, + L: Iterator<Item = S>, { block: Option<Block<'b>>, /// Items to be displayed @@ -22,9 +23,10 @@ where style: Style, } -impl<'b, L> ScrollableList<'b, L> +impl<'b, L, S> ScrollableList<'b, L, S> where - L: Iterator<Item = Span<'b>>, + S: Into<Text<'b>>, + L: Iterator<Item = S>, { fn new(items: L) -> Self { Self { @@ -40,9 +42,10 @@ where } } -impl<'b, L> Widget for ScrollableList<'b, L> +impl<'b, L, S> Widget for ScrollableList<'b, L, S> where - L: Iterator<Item = Span<'b>>, + S: Into<Text<'b>>, + L: Iterator<Item = S>, { fn render(self, area: Rect, buf: &mut Buffer) { // Render items @@ -55,7 +58,7 @@ where } } -pub fn draw_list<'b, B: Backend, L>( +pub fn draw_list<'b, B: Backend, L, S>( f: &mut Frame<B>, r: Rect, title: &'b str, @@ -63,7 +66,8 @@ pub fn draw_list<'b, B: Backend, L>( selected: bool, theme: &SharedTheme, ) where - L: Iterator<Item = Span<'b>>, + S: Into<Text<'b>>, + L: Iterator<Item = S>, { let list = ScrollableList::new(items).block( Block::default() @@ -74,13 +78,14 @@ pub fn draw_list<'b, B: Backend, L>( f.render_widget(list, r); } -pub fn draw_list_block<'b, B: Backend, L>( +pub fn draw_list_block<'b, B: Backend, L, S>( f: &mut Frame<B>, r: Rect, block: Block<'b>, items: L, ) where - L: Iterator<Item = Span<'b>>, + S: Into<Text<'b>>, + L: Iterator<Item = S>, { let list = ScrollableList::new(items).block(block); f.render_widget(list, r); diff --git a/src/ui/style.rs b/src/ui/style.rs index 7892304c..7579c9db 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -117,7 +117,8 @@ impl Theme { pub fn text(&self, enabled: bool, selected: bool) -> Style { match (enabled, selected) { - (false, _) => Style::default().fg(self.disabled_fg), + (false, false) => Style::default().fg(self.disabled_fg), + (false, true) => Style::default().bg(self.selection_bg), (true, false) => Style::default(), (true, true) => Style::default() .fg(self.command_fg) |