fix(tui): add width bounds and y‑position clamp for popups

- Limit popup width to a configurable range (40‑80 characters) and ensure a minimum width of 1.
- Preserve original width when the terminal is narrower than the minimum.
- Clamp the y coordinate to the top of the area to avoid negative positioning.
This commit is contained in:
2025-10-13 23:04:36 +02:00
parent c997b19b53
commit 6923ee439f

View File

@@ -3768,17 +3768,21 @@ fn render_command_suggestions(frame: &mut Frame<'_>, app: &ChatApp) {
let mut height = visible_count.saturating_mul(2).saturating_add(6); let mut height = visible_count.saturating_mul(2).saturating_add(6);
height = height.clamp(6, area.height); height = height.clamp(6, area.height);
let mut width = area.width.saturating_sub(10); let max_width: u16 = 80;
if width < 50 { let min_width: u16 = 40;
width = area.width.saturating_sub(4); let mut width = area.width.min(max_width);
} if area.width >= min_width {
if width == 0 { width = width.max(min_width);
} else {
width = area.width; width = area.width;
} }
let width = width.min(area.width); width = width.max(1);
let x = area.x + (area.width.saturating_sub(width)) / 2; let x = area.x + (area.width.saturating_sub(width)) / 2;
let y = area.y + (area.height.saturating_sub(height)) / 3; let mut y = area.y + (area.height.saturating_sub(height)) / 3;
if y < area.y {
y = area.y;
}
let popup_area = Rect::new(x, y, width, height); let popup_area = Rect::new(x, y, width, height);
frame.render_widget(Clear, popup_area); frame.render_widget(Clear, popup_area);