Skip to content

Commit

Permalink
Add a decent header line
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 4, 2019
1 parent c8914ab commit 9d430a2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
51 changes: 51 additions & 0 deletions src/interactive/widgets/header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Modifier, Style};
use tui::widgets::{Paragraph, Text, Widget};

pub struct Header;

impl Widget for Header {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
let bg_color = Color::LightYellow;
let text_color = Color::Black;
let standard = Style {
fg: text_color,
bg: bg_color,
..Default::default()
};
let modified = |text: &'static str, modifier| {
Text::Styled(
text.into(),
Style {
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 lines = [
bold(" D"),
text("isk "),
bold("U"),
text("sage "),
bold("A"),
text("alyzer v"),
text(env!("CARGO_PKG_VERSION")),
text(" "),
italic("(press "),
modified("?", Modifier::BOLD|Modifier::UNDERLINED),
italic(" for help)"),
];
Paragraph::new(lines.iter())
.style(Style {
fg: text_color,
bg: bg_color,
..Default::default()
})
.draw(area, buf);
}
}
2 changes: 1 addition & 1 deletion src/interactive/widgets/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Widget for HelpPane {
"close the current pain. Closes the application if no pane is open.",
);
hotkey("<tab>", "Cycle between all open panes");
hotkey("?", "Show the help pane");
hotkey("?", "Show or hide the help pane");
spacer();
}
title("Keys for Navigation");
Expand Down
15 changes: 12 additions & 3 deletions src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
interactive::{
widgets::{Entries, Footer, HelpPane, ListState},
widgets::{Entries, Footer, Header, HelpPane, ListState},
AppState, DisplayOptions, FocussedPane,
},
traverse::Traversal,
Expand Down Expand Up @@ -44,9 +44,16 @@ impl<'a, 'b, 'c> Widget for MainWindow<'a, 'b, 'c> {
} = self;
let regions = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Max(256), Constraint::Length(1)].as_ref())
.constraints(
[
Constraint::Length(1),
Constraint::Max(256),
Constraint::Length(1),
]
.as_ref(),
)
.split(area);
let (entries_area, footer_area) = (regions[0], regions[1]);
let (header_area, entries_area, footer_area) = (regions[0], regions[1], regions[2]);
let (entries_area, help_area_state) = match state.help_pane {
Some(state) => {
let regions = Layout::default()
Expand All @@ -70,6 +77,8 @@ impl<'a, 'b, 'c> Widget for MainWindow<'a, 'b, 'c> {
FocussedPane::Main => (white, grey),
FocussedPane::Help => (grey, white),
};

Header.draw(header_area, buf);
Entries {
tree: &tree,
root: state.root,
Expand Down
2 changes: 2 additions & 0 deletions src/interactive/widgets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
mod entries;
mod footer;
mod header;
mod help;
mod list;
mod main;

pub use entries::*;
pub use footer::*;
pub use header::*;
pub use help::*;
pub use list::*;
pub use main::*;

0 comments on commit 9d430a2

Please sign in to comment.