summaryrefslogtreecommitdiff
path: root/helix-term/src/ui/info.rs
diff options
context:
space:
mode:
authorKirawi2021-08-09 06:46:58 +0000
committerGitHub2021-08-09 06:46:58 +0000
commit815ee9e334da0b973510e1b956eb75fe437038da (patch)
tree0ab1b21f817eb21c64387ff7acc61bdc9a9caaba /helix-term/src/ui/info.rs
parentb5223618ed45cb6c67956795548f0963d570a5b2 (diff)
fix small terminal size panic with info popup (#563)
* fix small terminal size panic with info popup * remove unused enumerator * fix subtraction overflow panic
Diffstat (limited to 'helix-term/src/ui/info.rs')
-rw-r--r--helix-term/src/ui/info.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs
index 36b096db..6e810b86 100644
--- a/helix-term/src/ui/info.rs
+++ b/helix-term/src/ui/info.rs
@@ -7,24 +7,32 @@ use tui::widgets::{Block, Borders, Widget};
impl Component for Info {
fn render(&self, viewport: Rect, surface: &mut Surface, cx: &mut Context) {
let style = cx.editor.theme.get("ui.popup");
+
+ // Calculate the area of the terminal to modify. Because we want to
+ // render at the bottom right, we use the viewport's width and height
+ // which evaluate to the most bottom right coordinate.
+ let (width, height) = (self.width + 2, self.height + 2);
+ let area = viewport.intersection(Rect::new(
+ viewport.width.saturating_sub(width),
+ viewport.height.saturating_sub(height + 2),
+ width,
+ height,
+ ));
+ surface.clear_with(area, style);
+
let block = Block::default()
.title(self.title.as_str())
.borders(Borders::ALL)
.border_style(style);
- let Info { width, height, .. } = self;
- let (w, h) = (*width + 2, *height + 2);
- // -2 to subtract command line + statusline. a bit of a hack, because of splits.
- let area = viewport.intersection(Rect::new(
- viewport.width.saturating_sub(w),
- viewport.height.saturating_sub(h + 2),
- w,
- h,
- ));
- surface.clear_with(area, style);
- let Rect { x, y, .. } = block.inner(area);
- for (y, line) in (y..).zip(self.text.lines()) {
- surface.set_string(x, y, line, style);
- }
+ let inner = block.inner(area);
block.render(area, surface);
+
+ // Only write as many lines as there are rows available.
+ for (y, line) in (inner.y..)
+ .zip(self.text.lines())
+ .take(inner.height as usize)
+ {
+ surface.set_string(inner.x, y, line, style);
+ }
}
}