Skip to content

Commit

Permalink
auto-help which follows through the panes
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 29, 2020
1 parent a3cf6d6 commit ac04d9e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/interactive/widgets/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
);
}
}
}
}
25 changes: 23 additions & 2 deletions src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
);
}
}
}
}

0 comments on commit ac04d9e

Please sign in to comment.