diff options
-rw-r--r-- | Cargo.lock | 40 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/interactive/widgets/entries.rs | 30 | ||||
-rw-r--r-- | src/interactive/widgets/footer.rs | 49 | ||||
-rw-r--r-- | src/interactive/widgets/header.rs | 21 | ||||
-rw-r--r-- | src/interactive/widgets/help.rs | 48 | ||||
-rw-r--r-- | src/interactive/widgets/main.rs | 11 | ||||
-rw-r--r-- | src/interactive/widgets/mark.rs | 73 | ||||
-rw-r--r-- | src/interactive/widgets/mod.rs | 8 | ||||
-rw-r--r-- | tui-react/Cargo.toml | 4 | ||||
-rw-r--r-- | tui-react/src/lib.rs | 4 | ||||
-rw-r--r-- | tui-react/src/list.rs | 12 |
12 files changed, 161 insertions, 143 deletions
@@ -205,8 +205,8 @@ checksum = "032534543c938ffc4106ee75411f4b7be2e0260e044d17dae36f9409ada87895" dependencies = [ "crossterm", "termion", - "tui", - "tui-react 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tui 0.9.5", + "tui-react 0.4.1", ] [[package]] @@ -242,8 +242,8 @@ dependencies = [ "petgraph", "pretty_assertions", "structopt", - "tui", - "tui-react 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tui 0.10.0", + "tui-react 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation", "wild", ] @@ -708,23 +708,47 @@ dependencies = [ ] [[package]] +name = "tui" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a977b0bb2e2033a6fef950f218f13622c3c34e59754b704ce3492dedab1dfe95" +dependencies = [ + "bitflags", + "cassowary", + "unicode-segmentation", + "unicode-width", +] + +[[package]] name = "tui-react" version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94a0de793b78a2275af97d92666d52e00b7938518d1668c6f9a09eca2d4a69df" dependencies = [ "log", - "tui", + "tui 0.9.5", "unicode-segmentation", "unicode-width", ] [[package]] name = "tui-react" -version = "0.4.1" +version = "0.10.0" +dependencies = [ + "log", + "tui 0.10.0", + "unicode-segmentation", + "unicode-width", +] + +[[package]] +name = "tui-react" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94a0de793b78a2275af97d92666d52e00b7938518d1668c6f9a09eca2d4a69df" +checksum = "21bbc5221de660fa2cc79a5386d72f268174a90e37eef004f5210cc7f94baf78" dependencies = [ "log", - "tui", + "tui 0.10.0", "unicode-segmentation", "unicode-width", ] @@ -31,8 +31,8 @@ colored = "2.0.0" # 'tui' related unicode-segmentation = { version = "1.3.0", optional = true } crosstermion = { optional = true, version = "0.2.0", default-features = false } -tui = { version = "0.9.1", optional = true, default-features = false } -tui-react = { version = "0.4", optional = true } +tui = { version = "0.10.0", optional = true, default-features = false } +tui-react = { version = "0.10", optional = true } open = { version = "1.2.2", optional = true } wild = "2.0.4" 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::<Vec<_>>(), + ))) + .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<Color>, is_file: bool, is_marked: bool) -> Option<Color> { 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, } } diff --git a/tui-react/Cargo.toml b/tui-react/Cargo.toml index 4929d98..7fb2055 100644 --- a/tui-react/Cargo.toml +++ b/tui-react/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tui-react" -version = "0.4.1" +version = "0.10.0" authors = ["Sebastian Thiel <sthiel@thoughtworks.com>"] edition = "2018" repository = "https://github.com/Byron/dua-cli" @@ -9,7 +9,7 @@ readme = "README.md" license = "MIT" [dependencies] -tui = { version = "0.9.1", default-features = false } +tui = { version = "0.10.0", default-features = false } log = "0.4.6" unicode-segmentation = "1.6.0" unicode-width = "0.1.7" diff --git a/tui-react/src/lib.rs b/tui-react/src/lib.rs index 16370e5..9333fb5 100644 --- a/tui-react/src/lib.rs +++ b/tui-react/src/lib.rs @@ -54,7 +54,7 @@ pub fn draw_text_with_ellipsis_nowrap( } cell.symbol = g.into(); if let Some(s) = s { - cell.style = s; + cell.set_style(s); } x_offset += width.saturating_sub(1) as u16; @@ -86,7 +86,7 @@ pub fn draw_text_nowrap_fn( for (g, x) in t.as_ref().graphemes(true).zip(bound.left()..bound.right()) { let cell = buf.get_mut(x, bound.y); cell.symbol = g.into(); - cell.style = s(&cell.symbol, x, bound.y); + cell.set_style(s(&cell.symbol, x, bound.y)); } } diff --git a/tui-react/src/list.rs b/tui-react/src/list.rs index 8ffe88c..16e2a91 100644 --- a/tui-react/src/list.rs +++ b/tui-react/src/list.rs @@ -1,7 +1,8 @@ use tui::{ buffer::Buffer, layout::Rect, - widgets::{Block, Paragraph, Text, Widget}, + text::{Span, Spans, Text}, + widgets::{Block, Paragraph, Widget}, }; #[derive(Default)] @@ -33,7 +34,7 @@ impl List { pub fn render<'a, 't>( &mut self, props: ListProps<'a>, - items: impl IntoIterator<Item = Vec<Text<'t>>>, + items: impl IntoIterator<Item = Vec<Span<'t>>>, area: Rect, buf: &mut Buffer, ) { @@ -44,8 +45,9 @@ impl List { let list_area = match block { Some(b) => { + let area = b.inner(area); b.render(area, buf); - b.inner(area) + area } None => area, }; @@ -55,14 +57,14 @@ impl List { return; } - for (i, text_iterator) in items + for (i, vec_of_spans) in items .into_iter() .skip(self.offset) .enumerate() .take(list_area.height as usize) { let (x, y) = (list_area.left(), list_area.top() + i as u16); - Paragraph::new(text_iterator.iter()).render( + Paragraph::new(Text::from(Spans::from(vec_of_spans))).render( Rect { x, y, |