summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2020-07-22 10:45:40 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-07-22 10:45:40 +0800
commit839b9323d93b9f562f6414cd66504b6d686c0224 (patch)
treedec25a406b00786c03d7afc3e683f54a4dd632e4
parent773497cc48a406a069be84e14194d51484fdbec2 (diff)
Upgrade to tui 0.10 step one…tui-react-v0.10.0
…which can be followed by a crosstermion upgrade once prodash/crosstermion have caught up.
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml4
-rw-r--r--src/interactive/widgets/entries.rs30
-rw-r--r--src/interactive/widgets/footer.rs49
-rw-r--r--src/interactive/widgets/header.rs21
-rw-r--r--src/interactive/widgets/help.rs48
-rw-r--r--src/interactive/widgets/main.rs11
-rw-r--r--src/interactive/widgets/mark.rs73
-rw-r--r--src/interactive/widgets/mod.rs8
9 files changed, 120 insertions, 128 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b758aa7..96a598f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -242,8 +242,8 @@ dependencies = [
"petgraph",
"pretty_assertions",
"structopt",
- "tui 0.9.5",
- "tui-react 0.4.1",
+ "tui 0.10.0",
+ "tui-react 0.10.0",
"unicode-segmentation",
"wild",
]
diff --git a/Cargo.toml b/Cargo.toml
index 470efbb..7067b9f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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, path = "tui-react" }
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,
}
}