palette: scale popup with terminal size, key hints

This commit is contained in:
hermes authored and Johannes Kresner committed 2026-10-02 23:31:55 +02:00
1 parent 89eb1571ea
commit 4a8e920ab8
1 file changed
+9 -4
+9 -4
View File
@@ -132,11 +132,15 @@ impl Picker {
pub fn draw(&self, f: &mut ratatui::Frame) {
let th = theme::t();
let a = f.area();
let w = a.width.saturating_sub(4).min(80);
// scales with the terminal: 60% of the width, 50..=110 cols, never wider than the screen
let w = (a.width * 6 / 10).clamp(50, 110).min(a.width.saturating_sub(4));
let ms = self.matches();
// borders + query line + spacer
let h = (ms.len() as u16 + 4).min(a.height.saturating_sub(2)).max(5);
let r = Rect::new(a.x + (a.width - w) / 2, a.y + 1, w, h);
let h = (ms.len() as u16 + 4)
.min((a.height * 6 / 10).max(8))
.min(a.height.saturating_sub(2))
.max(5);
let r = Rect::new(a.x + (a.width - w) / 2, a.y + a.height / 8, w, h);
let rows = (h - 4) as usize;
let top = self.sel.saturating_sub(rows.saturating_sub(1));
let lw = ms
@@ -165,7 +169,8 @@ impl Picker {
Paragraph::new(lines).block(
Block::bordered()
.border_style(th.dim())
.title(Span::styled(" ctrl-p ", th.dim())),
.title(Span::styled(" ctrl-p ", th.dim()))
.title_bottom(Span::styled(" ↑↓ select · ⏎ run · esc close ", th.dim())),
),
r,
);