Skip to content

Commit

Permalink
help comes to live, slowly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 4, 2019
1 parent e522160 commit 286bfd4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
32 changes: 28 additions & 4 deletions src/interactive/widgets/help.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use tui::{
buffer::Buffer, layout::Rect, style::Style, widgets::Block, widgets::Borders, widgets::Widget,
buffer::Buffer,
layout::Rect,
style::{Modifier, Style},
widgets::{Block, Borders, Paragraph, Text, Widget},
};

#[derive(Copy, Clone)]
Expand All @@ -12,10 +15,31 @@ pub struct HelpPane {

impl Widget for HelpPane {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
Block::default()
fn title(name: &str) -> Text {
Text::Styled(
format!("{}\n\n", name).into(),
Style {
modifier: Modifier::BOLD,
..Default::default()
},
)
};
fn hotkey(keys: &str, description: &str) -> Text<'static> {
Text::Styled(
format!("{} => {}\n", keys, description).into(),
Style {
..Default::default()
},
)
};

let mut block = Block::default()
.title("Help")
.border_style(self.border_style)
.borders(Borders::ALL)
.draw(area, buf);
.borders(Borders::ALL);
block.draw(area, buf);
let area = block.inner(area).inner(1);

Paragraph::new([title("Hotkeys"), hotkey("j", "move down")].iter()).draw(area, buf);
}
}
10 changes: 5 additions & 5 deletions src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ impl<'a, 'b, 'c> Widget for MainWindow<'a, 'b, 'c> {
}
None => (entries_area, None),
};
let grey = || Style {
let grey = Style {
fg: Color::DarkGray,
bg: Color::Reset,
modifier: Modifier::empty(),
};
let white = || Style {
let white = Style {
fg: Color::White,
..grey()
..grey
};
let (entries_style, help_style) = match state.focussed {
FocussedPane::Main => (white(), grey()),
FocussedPane::Help => (grey(), white()),
FocussedPane::Main => (white, grey),
FocussedPane::Help => (grey, white),
};
Entries {
tree: &tree,
Expand Down

0 comments on commit 286bfd4

Please sign in to comment.