diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-03-29 22:30:41 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-03-29 22:30:41 +0800 |
commit | d5ed498b592ff2b7f725163cae0c8426930c005c (patch) | |
tree | 86e97de1c42cd7235a19551d0031f904230df5bb /src/interactive | |
parent | ac04d9ed9992090cfaf0002c2da954fefd542241 (diff) |
navigation help for 'help' pane :D
Diffstat (limited to 'src/interactive')
-rw-r--r-- | src/interactive/widgets/help.rs | 30 | ||||
-rw-r--r-- | src/interactive/widgets/main.rs | 5 |
2 files changed, 33 insertions, 2 deletions
diff --git a/src/interactive/widgets/help.rs b/src/interactive/widgets/help.rs index f758386..8b40542 100644 --- a/src/interactive/widgets/help.rs +++ b/src/interactive/widgets/help.rs @@ -11,6 +11,10 @@ use tui::{ style::{Modifier, Style}, widgets::{Block, Borders, Paragraph, Text, Widget}, }; +use tui_react::{ + draw_text_nowrap_fn, + util::{block_width, rect}, +}; #[derive(Default, Clone)] pub struct HelpPane { @@ -19,6 +23,7 @@ pub struct HelpPane { pub struct HelpPaneProps { pub border_style: Style, + pub has_focus: bool, } fn margin(r: Rect, margin: u16) -> Rect { @@ -174,14 +179,35 @@ impl HelpPane { (lines.into_inner(), num_lines.get()) }; - let HelpPaneProps { border_style } = props.borrow(); + let HelpPaneProps { + border_style, + has_focus, + } = props.borrow(); + let title = "Help"; let mut block = Block::default() - .title("Help") + .title(title) .border_style(*border_style) .borders(Borders::ALL); block.draw(area, buf); + if *has_focus { + let help_text = " . = o|.. = u || ⇊ = CTRL+d|↓ = j|⇈ = CTRL+u|↑ = k "; + let help_text_block_width = block_width(help_text); + let bound = Rect { + width: area.width.saturating_sub(1), + ..area + }; + if block_width(title) + help_text_block_width <= bound.width { + draw_text_nowrap_fn( + rect::snap_to_right(bound, help_text_block_width), + buf, + help_text, + |_, _, _| Style::default(), + ); + } + } + let area = margin(block.inner(area), 1); self.scroll = self.scroll.min(num_lines.saturating_sub(area.height)); Paragraph::new(texts.iter()) diff --git a/src/interactive/widgets/main.rs b/src/interactive/widgets/main.rs index 8a43a01..fe8c358 100644 --- a/src/interactive/widgets/main.rs +++ b/src/interactive/widgets/main.rs @@ -117,6 +117,11 @@ impl MainWindow { if let Some((help_area, pane)) = help_pane { let props = HelpPaneProps { border_style: help_style, + has_focus: if let Help = state.focussed { + true + } else { + false + }, }; pane.render(props, help_area, buf); } |