summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPiotr Wach <pwach@bloomberg.net>2023-12-20 21:04:59 +0100
committerPiotr Wach <pwach@bloomberg.net>2023-12-20 21:04:59 +0100
commitff07f3935bc0a82e52bc169d2739a9bb603d86b8 (patch)
tree84fad00360e5d374685771166b70d05f3154b75f /src
parent0a344fa063bdffe7165e8bab6b8a1b8adbac9dce (diff)
Glob most used keys
Diffstat (limited to 'src')
-rw-r--r--src/interactive/widgets/glob.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/interactive/widgets/glob.rs b/src/interactive/widgets/glob.rs
index 51fff3d..69f932e 100644
--- a/src/interactive/widgets/glob.rs
+++ b/src/interactive/widgets/glob.rs
@@ -6,13 +6,15 @@ use petgraph::Direction;
use std::borrow::Borrow;
use std::path::PathBuf;
use tui::backend::Backend;
+use tui::prelude::Buffer;
use tui::{
layout::Rect,
style::Style,
text::{Line, Span, Text},
widgets::{Block, Borders, Paragraph, Widget},
};
-use tui_react::Terminal;
+use tui_react::util::{block_width, rect};
+use tui_react::{draw_text_nowrap_fn, Terminal};
use crate::interactive::Cursor;
@@ -121,6 +123,8 @@ impl GlobPane {
);
if *has_focus {
+ draw_top_right_help(area, title, terminal.current_buffer_mut());
+
cursor.show = true;
cursor.x = inner_block_area.x + self.cursor_position as u16 + 1;
cursor.y = inner_block_area.y;
@@ -130,6 +134,24 @@ impl GlobPane {
}
}
+fn draw_top_right_help(area: Rect, title: &str, buf: &mut Buffer) -> Rect {
+ let help_text = " search = enter | cancel = esc ";
+ 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(),
+ );
+ }
+ bound
+}
+
fn margin_left_right(r: Rect, margin: u16) -> Rect {
Rect {
x: r.x + margin,