From 8c1f58079f4917a75f6818ac6fda6aaf4ecc55d6 Mon Sep 17 00:00:00 2001 From: Florian Dehau Date: Sun, 17 Oct 2021 17:12:50 +0200 Subject: [PATCH] chore: fix build --- CHANGELOG.md | 4 +++- src/widgets/list.rs | 12 +++++++++--- tests/widgets_list.rs | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd7a6df..8768b37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # Changelog ## To be released + ### Features -* Add option to `widgets::List` to repeat the hightlight symbol for each line of multi-line items. + +* Add option to `widgets::List` to repeat the hightlight symbol for each line of multi-line items (#533). ## v0.16.0 - 2021-08-01 diff --git a/src/widgets/list.rs b/src/widgets/list.rs index 6fe06bd..5f6a559 100644 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -126,7 +126,7 @@ impl<'a> List<'a> { self.highlight_style = style; self } - + pub fn repeat_highlight_symbol(mut self, repeat: bool) -> List<'a> { self.repeat_highlight_symbol = repeat; self @@ -239,13 +239,19 @@ impl<'a> StatefulWidget for List<'a> { // if the item is selected, we need to display the hightlight symbol: // - either for the first line of the item only, // - or for each line of the item if the appropriate option is set - let symbol = if is_selected && (j == 0 || self.repeat_highlight_symbol){ + let symbol = if is_selected && (j == 0 || self.repeat_highlight_symbol) { highlight_symbol } else { &blank_symbol }; let (elem_x, max_element_width) = if has_selection { - let (elem_x, _) = buf.set_stringn(x, y + j as u16, symbol, list_area.width as usize, item_style); + let (elem_x, _) = buf.set_stringn( + x, + y + j as u16, + symbol, + list_area.width as usize, + item_style, + ); (elem_x, (list_area.width - (elem_x - x)) as u16) } else { (x, list_area.width) diff --git a/tests/widgets_list.rs b/tests/widgets_list.rs index 945afba..019aaf6 100644 --- a/tests/widgets_list.rs +++ b/tests/widgets_list.rs @@ -4,6 +4,7 @@ use tui::{ layout::Rect, style::{Color, Style}, symbols, + text::Spans, widgets::{Block, Borders, List, ListItem, ListState}, Terminal, }; @@ -153,7 +154,8 @@ fn widgets_list_should_display_multiline_items() { ">> Item 2 ", " Item 2b", " Item 3 ", - " Item 3c"]); + " Item 3c", + ]); for x in 0..10 { expected.get_mut(x, 2).set_bg(Color::Yellow); expected.get_mut(x, 3).set_bg(Color::Yellow); @@ -188,7 +190,8 @@ fn widgets_list_should_repeat_highlight_symbol() { ">> Item 2 ", ">> Item 2b", " Item 3 ", - " Item 3c"]); + " Item 3c", + ]); for x in 0..10 { expected.get_mut(x, 2).set_bg(Color::Yellow); expected.get_mut(x, 3).set_bg(Color::Yellow);