Skip to content

Commit

Permalink
Upgrade to tui 0.10 step one…
Browse files Browse the repository at this point in the history
…which can be followed by a crosstermion upgrade once
prodash/crosstermion have caught up.
  • Loading branch information
Byron committed Jul 22, 2020
1 parent 773497c commit 839b932
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 128 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
30 changes: 14 additions & 16 deletions src/interactive/widgets/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -107,50 +108,47 @@ 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}{}",
w.name.to_string_lossy(),
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 }
},
Expand Down
49 changes: 25 additions & 24 deletions src/interactive/widgets/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
21 changes: 11 additions & 10 deletions src/interactive/widgets/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@ use tui::{
buffer::Buffer,
layout::Rect,
style::{Color, Modifier, Style},
widgets::{Paragraph, Text, Widget},
text::{Span, Spans, Text},
widgets::{Paragraph, Widget},
};

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"),
Expand All @@ -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);
Expand Down
48 changes: 21 additions & 27 deletions src/interactive/widgets/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
},
));
Expand All @@ -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
)));
}
};

Expand Down Expand Up @@ -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);
}
}
11 changes: 6 additions & 5 deletions src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 839b932

Please sign in to comment.