summaryrefslogtreecommitdiffstats
path: root/src/interactive/widgets/help.rs
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2020-03-29 22:30:41 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-03-29 22:30:41 +0800
commitd5ed498b592ff2b7f725163cae0c8426930c005c (patch)
tree86e97de1c42cd7235a19551d0031f904230df5bb /src/interactive/widgets/help.rs
parentac04d9ed9992090cfaf0002c2da954fefd542241 (diff)
navigation help for 'help' pane :D
Diffstat (limited to 'src/interactive/widgets/help.rs')
-rw-r--r--src/interactive/widgets/help.rs30
1 files changed, 28 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())