diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-03-29 22:22:42 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-03-29 22:22:42 +0800 |
commit | ac04d9ed9992090cfaf0002c2da954fefd542241 (patch) | |
tree | 28f172d4868518a86c3318564922fd369f1535e1 /src/interactive | |
parent | a3cf6d6f3ea68d4cc91a433b4e3701e698f27009 (diff) |
auto-help which follows through the panes
Diffstat (limited to 'src/interactive')
-rw-r--r-- | src/interactive/widgets/entries.rs | 23 | ||||
-rw-r--r-- | src/interactive/widgets/mark.rs | 25 |
2 files changed, 45 insertions, 3 deletions
diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs index adb8a08..9f483e4 100644 --- a/src/interactive/widgets/entries.rs +++ b/src/interactive/widgets/entries.rs @@ -12,7 +12,11 @@ use tui::{ style::{Color, Modifier, Style}, widgets::{Block, Borders, Text}, }; -use tui_react::{fill_background_to_right, List, ListProps}; +use tui_react::{ + draw_text_nowrap_fn, fill_background_to_right, + util::{block_width, rect}, + List, ListProps, +}; pub struct EntriesProps<'a> { pub tree: &'a Tree, @@ -155,5 +159,22 @@ impl Entries { ); list.render(props, lines, area, buf); + + if *is_focussed { + 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(), + ); + } + } } } diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index 8f8ef7c..96b9862 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -18,7 +18,11 @@ use tui::{ widgets::Text, widgets::{Paragraph, Widget}, }; -use tui_react::{List, ListProps}; +use tui_react::{ + draw_text_nowrap_fn, + util::{block_width, rect}, + List, ListProps, +}; use unicode_segmentation::UnicodeSegmentation; pub enum MarkMode { @@ -366,6 +370,23 @@ impl MarkPane { block: None, entry_in_view, }; - self.list.render(props, entries, list_area, buf) + self.list.render(props, entries, list_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(), + ); + } + } } } |