From 839b9323d93b9f562f6414cd66504b6d686c0224 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 22 Jul 2020 10:45:40 +0800 Subject: =?UTF-8?q?Upgrade=20to=20tui=200.10=20step=20one=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …which can be followed by a crosstermion upgrade once prodash/crosstermion have caught up. --- src/interactive/widgets/entries.rs | 30 ++++++++-------- src/interactive/widgets/footer.rs | 49 ++++++++++++------------- src/interactive/widgets/header.rs | 21 +++++------ src/interactive/widgets/help.rs | 48 +++++++++++-------------- src/interactive/widgets/main.rs | 11 +++--- src/interactive/widgets/mark.rs | 73 ++++++++++++++++++-------------------- src/interactive/widgets/mod.rs | 8 ++--- 7 files changed, 116 insertions(+), 124 deletions(-) (limited to 'src') diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs index 279a7fa..62d24e3 100644 --- a/src/interactive/widgets/entries.rs +++ b/src/interactive/widgets/entries.rs @@ -10,7 +10,8 @@ use tui::{ buffer::Buffer, layout::Rect, style::{Color, Modifier, Style}, - widgets::{Block, Borders, Text}, + text::Span, + widgets::{Block, Borders}, }; use tui_react::util::rect::line_bound; use tui_react::{ @@ -78,7 +79,7 @@ impl Entries { } ); let block = Block::default() - .title(&title) + .title(title.as_str()) .border_style(*border_style) .borders(Borders::ALL); let entry_in_view = selected.map(|selected| { @@ -107,34 +108,32 @@ impl Entries { false }; if is_selected { - style.modifier.insert(Modifier::REVERSED); + style.add_modifier.insert(Modifier::REVERSED); } if *is_focussed & is_selected { - style.modifier.insert(Modifier::BOLD); + style.add_modifier.insert(Modifier::BOLD); } - let bytes = Text::Styled( + let bytes = Span::styled( format!( "{:>byte_column_width$}", display.byte_format.display(w.size).to_string(), // we would have to impl alignment/padding ourselves otherwise... byte_column_width = display.byte_format.width() - ) - .into(), + ), Style { - fg: Color::Green, + fg: Color::Green.into(), ..style }, ); - let percentage = Text::Styled( + let percentage = Span::styled( format!( " |{}| ", display.byte_vis.display(w.size as f32 / total as f32) - ) - .into(), + ), style, ); - let name = Text::Styled( + let name = Span::styled( fill_background_to_right( format!( "{prefix}{}", @@ -142,15 +141,14 @@ impl Entries { prefix = if *is_dir && !is_top(*root) { "/" } else { " " } ), area.width, - ) - .into(), + ), { let is_marked = marked.map(|m| m.contains_key(node_idx)).unwrap_or(false); let fg = if !exists { // non-existing - always red! - Color::Red + Some(Color::Red) } else { - entry_color(style.fg, !is_dir, is_marked) + entry_color(style.fg, !*is_dir, is_marked) }; Style { fg, ..style } }, diff --git a/src/interactive/widgets/footer.rs b/src/interactive/widgets/footer.rs index 190c6c9..2c2843b 100644 --- a/src/interactive/widgets/footer.rs +++ b/src/interactive/widgets/footer.rs @@ -5,7 +5,8 @@ use tui::{ layout::Rect, style::Modifier, style::{Color, Style}, - widgets::{Paragraph, Text, Widget}, + text::{Span, Spans, Text}, + widgets::{Paragraph, Widget}, }; pub struct Footer; @@ -26,35 +27,35 @@ impl Footer { message, } = props.borrow(); - let lines = [ - Text::Raw( - format!( - " Total disk usage: {} Entries: {} ", - match total_bytes { - Some(b) => format!("{}", format.display(*b)), - None => "-".to_owned(), - }, - entries_traversed, - ) - .into(), - ) + let spans = vec![ + Span::from(format!( + " Total disk usage: {} Entries: {} ", + match total_bytes { + Some(b) => format!("{}", format.display(*b)), + None => "-".to_owned(), + }, + entries_traversed, + )) .into(), message.as_ref().map(|m| { - Text::Styled( - m.into(), + Span::styled( + m, Style { - fg: Color::Red, - bg: Color::Reset, - modifier: Modifier::BOLD | Modifier::RAPID_BLINK, + fg: Color::Red.into(), + bg: Color::Reset.into(), + add_modifier: Modifier::BOLD | Modifier::RAPID_BLINK, + ..Style::default() }, ) }), ]; - Paragraph::new(lines.iter().filter_map(|x| x.as_ref())) - .style(Style { - modifier: Modifier::REVERSED, - ..Default::default() - }) - .render(area, buf); + Paragraph::new(Text::from(Spans::from( + spans + .into_iter() + .filter_map(std::convert::identity) + .collect::>(), + ))) + .style(Style::default().add_modifier(Modifier::REVERSED)) + .render(area, buf); } } diff --git a/src/interactive/widgets/header.rs b/src/interactive/widgets/header.rs index 745db3c..49106b2 100644 --- a/src/interactive/widgets/header.rs +++ b/src/interactive/widgets/header.rs @@ -2,7 +2,8 @@ use tui::{ buffer::Buffer, layout::Rect, style::{Color, Modifier, Style}, - widgets::{Paragraph, Text, Widget}, + text::{Span, Spans, Text}, + widgets::{Paragraph, Widget}, }; pub struct Header; @@ -10,25 +11,25 @@ pub struct Header; impl Header { pub fn render(&self, bg_color: Color, area: Rect, buf: &mut Buffer) { let standard = Style { - fg: Color::Black, - bg: bg_color, + fg: Color::Black.into(), + bg: bg_color.into(), ..Default::default() }; debug_assert_ne!(standard.bg, standard.fg); let modified = |text: &'static str, modifier| { - Text::Styled( - text.into(), + Span::styled( + text, Style { - modifier, + add_modifier: modifier, ..standard }, ) }; let bold = |text: &'static str| modified(text, Modifier::BOLD); let italic = |text: &'static str| modified(text, Modifier::UNDERLINED); - let text = |text: &'static str| Text::Styled(text.into(), standard); + let text = |text: &'static str| Span::styled(text, standard); - let lines = [ + let spans = vec![ bold(" D"), text("isk "), bold("U"), @@ -41,9 +42,9 @@ impl Header { modified("?", Modifier::BOLD | Modifier::UNDERLINED), italic(" for help)"), ]; - Paragraph::new(lines.iter()) + Paragraph::new(Text::from(Spans::from(spans))) .style(Style { - bg: bg_color, + bg: bg_color.into(), ..Default::default() }) .render(area, buf); diff --git a/src/interactive/widgets/help.rs b/src/interactive/widgets/help.rs index 56cfaea..d0572df 100644 --- a/src/interactive/widgets/help.rs +++ b/src/interactive/widgets/help.rs @@ -7,9 +7,9 @@ use std::{ use tui::{ buffer::Buffer, layout::Rect, - style::Color, - style::{Modifier, Style}, - widgets::{Block, Borders, Paragraph, Text, Widget}, + style::{Color, Modifier, Style}, + text::{Span, Spans, Text}, + widgets::{Block, Borders, Paragraph, Widget}, }; use tui_react::{ draw_text_nowrap_fn, @@ -57,14 +57,14 @@ impl HelpPane { let spacer = || { count(2); - lines.borrow_mut().push(Text::Raw("\n\n".into())); + lines.borrow_mut().push(Span::from("\n\n")); }; let title = |name| { count(2); - lines.borrow_mut().push(Text::Styled( - format!("{}\n\n", name).into(), + lines.borrow_mut().push(Span::styled( + format!("{}\n\n", name), Style { - modifier: Modifier::BOLD | Modifier::UNDERLINED, + add_modifier: Modifier::BOLD | Modifier::UNDERLINED, ..Default::default() }, )); @@ -73,33 +73,27 @@ impl HelpPane { let separator_size = 3; let column_size = 11 + separator_size; count(1 + other_line.iter().count() as u16); - lines.borrow_mut().push(Text::Styled( + lines.borrow_mut().push(Span::styled( format!( "{:>column_size$}", keys, column_size = column_size - separator_size - ) - .into(), + ), Style { - fg: Color::Green, + fg: Color::Green.into(), ..Default::default() }, )); - lines.borrow_mut().push(Text::Styled( - format!(" => {}\n", description).into(), - Style::default(), - )); + lines + .borrow_mut() + .push(Span::from(format!(" => {}\n", description))); if let Some(second_line) = other_line { - lines.borrow_mut().push(Text::Styled( - format!( - "{:>column_size$}{}\n", - "", - second_line, - column_size = column_size + 1 - ) - .into(), - Style::default(), - )); + lines.borrow_mut().push(Span::from(format!( + "{:>column_size$}{}\n", + "", + second_line, + column_size = column_size + 1 + ))); } }; @@ -219,8 +213,8 @@ impl HelpPane { let area = margin(block.inner(area), 1); self.scroll = self.scroll.min(num_lines.saturating_sub(area.height)); - Paragraph::new(texts.iter()) - .scroll(self.scroll) + Paragraph::new(Text::from(Spans::from(texts))) + .scroll((self.scroll, 0)) .render(area, buf); } } diff --git a/src/interactive/widgets/main.rs b/src/interactive/widgets/main.rs index fe8c358..64755c9 100644 --- a/src/interactive/widgets/main.rs +++ b/src/interactive/widgets/main.rs @@ -50,13 +50,14 @@ impl MainWindow { let (entries_style, help_style, mark_style) = { let grey = Style { - fg: Color::DarkGray, - bg: Color::Reset, - modifier: Modifier::empty(), + fg: Color::DarkGray.into(), + bg: Color::Reset.into(), + add_modifier: Modifier::empty(), + ..Style::default() }; let bold = Style { - fg: Color::Rgb(230, 230, 230), - modifier: Modifier::BOLD, + fg: Color::Rgb(230, 230, 230).into(), + add_modifier: Modifier::BOLD, ..grey }; match state.focussed { diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index 7cc5e30..0ee4c09 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -16,7 +16,8 @@ use tui::{ buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, - widgets::{Block, Borders, Paragraph, Text, Widget}, + text::{Span, Spans, Text}, + widgets::{Block, Borders, Paragraph, Widget}, }; use tui_react::{ draw_text_nowrap_fn, @@ -236,14 +237,14 @@ impl MarkPane { let has_focus = self.has_focus; let entries = marked.values().sorted_by_key(|v| &v.index).enumerate().map( |(idx, v): (usize, &EntryMark)| { - let default_style = match selected { + let base_style = match selected { Some(selected) if idx == selected => { let mut modifier = Modifier::REVERSED; if has_focus { modifier.insert(Modifier::BOLD); } Style { - modifier, + add_modifier: modifier, ..Default::default() } } @@ -272,38 +273,36 @@ impl MarkPane { _ => (path, num_path_graphemes), } }; - let fg_path = entry_color(Color::Reset, !v.is_dir, true); - let path = Text::Styled( - path.into(), + let fg_path = entry_color(None, !v.is_dir, true); + let path = Span::styled( + path, Style { fg: fg_path, - ..default_style + ..Style::default() }, ); - let bytes = Text::Styled( + let bytes = Span::styled( format!( "{:>byte_column_width$} ", format.display(v.size).to_string(), // we would have to impl alignment/padding ourselves otherwise... byte_column_width = format.width() - ) - .into(), + ), Style { - fg: Color::Green, - ..default_style + fg: Color::Green.into(), + ..base_style }, ); - let spacer = Text::Styled( + let spacer = Span::styled( format!( "{:-space$}", "", space = (area.width as usize) .saturating_sub(path_len) .saturating_sub(format.total_width()) - ) - .into(), + ), Style { - fg: fg_path, - ..default_style + fg: fg_path.into(), + ..base_style }, ); vec![path, spacer, bytes] @@ -318,7 +317,7 @@ impl MarkPane { } }; let block = Block::default() - .title(&title) + .title(title.as_str()) .border_style(*border_style) .borders(Borders::ALL); @@ -348,27 +347,25 @@ impl MarkPane { }; let default_style = Style { - fg: Color::Black, - bg: Color::Yellow, - modifier: Modifier::BOLD, + fg: Color::Black.into(), + bg: Color::Yellow.into(), + add_modifier: Modifier::BOLD, + sub_modifier: Modifier::empty(), }; - Paragraph::new( - [ - Text::Styled( - " Ctrl + r".into(), - Style { - fg: Color::LightRed, - modifier: default_style.modifier | Modifier::RAPID_BLINK, - ..default_style - }, - ), - Text::Styled( - " deletes listed entries from disk without prompt".into(), - default_style, - ), - ] - .iter(), - ) + Paragraph::new(Text::from(Spans::from(vec![ + Span::styled( + " Ctrl + r", + Style { + fg: Color::LightRed.into(), + add_modifier: default_style.add_modifier | Modifier::RAPID_BLINK, + ..default_style + }, + ), + Span::styled( + " deletes listed entries from disk without prompt", + default_style, + ), + ]))) .style(default_style) .render(help_line_area, buf); list_area diff --git a/src/interactive/widgets/mod.rs b/src/interactive/widgets/mod.rs index 5e37423..dd1f8c3 100644 --- a/src/interactive/widgets/mod.rs +++ b/src/interactive/widgets/mod.rs @@ -17,11 +17,11 @@ use tui::style::Color; pub const COLOR_MARKED: Color = Color::Yellow; pub const COLOR_MARKED_DARK: Color = Color::Rgb(176, 126, 0); -fn entry_color(fg: Color, is_file: bool, is_marked: bool) -> Color { +fn entry_color(fg: Option, is_file: bool, is_marked: bool) -> Option { match (is_file, is_marked) { - (true, false) => Color::DarkGray, - (true, true) => COLOR_MARKED_DARK, - (false, true) => COLOR_MARKED, + (true, false) => Color::DarkGray.into(), + (true, true) => COLOR_MARKED_DARK.into(), + (false, true) => COLOR_MARKED.into(), _ => fg, } } -- cgit v1.2.3