palette: scale popup with terminal size, key hints
This commit is contained in:
1 parent
4c995149cf
commit
90c51de8a1
1 file changed
+9
-4
@@ -132,11 +132,15 @@ impl Picker {
|
|||||||
pub fn draw(&self, f: &mut ratatui::Frame) {
|
pub fn draw(&self, f: &mut ratatui::Frame) {
|
||||||
let th = theme::t();
|
let th = theme::t();
|
||||||
let a = f.area();
|
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();
|
let ms = self.matches();
|
||||||
// borders + query line + spacer
|
// borders + query line + spacer
|
||||||
let h = (ms.len() as u16 + 4).min(a.height.saturating_sub(2)).max(5);
|
let h = (ms.len() as u16 + 4)
|
||||||
let r = Rect::new(a.x + (a.width - w) / 2, a.y + 1, w, h);
|
.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 rows = (h - 4) as usize;
|
||||||
let top = self.sel.saturating_sub(rows.saturating_sub(1));
|
let top = self.sel.saturating_sub(rows.saturating_sub(1));
|
||||||
let lw = ms
|
let lw = ms
|
||||||
@@ -165,7 +169,8 @@ impl Picker {
|
|||||||
Paragraph::new(lines).block(
|
Paragraph::new(lines).block(
|
||||||
Block::bordered()
|
Block::bordered()
|
||||||
.border_style(th.dim())
|
.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,
|
r,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user