From 14c08e855f6d0ebfbf1d7cb5d7010507ad3a5db6 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Tue, 17 Aug 2021 05:55:48 +0530 Subject: Refactor infobox rendering and parsing (#579) --- helix-term/src/keymap.rs | 2 +- helix-term/src/ui/info.rs | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 1267eca2..57bcb321 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -145,7 +145,7 @@ impl From for Info { .map(|(desc, keys)| (desc.strip_prefix(&prefix).unwrap(), keys)) .collect(); } - Info::key(node.name(), body) + Info::new(node.name(), body) } } diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs index 0f14260e..0da0fe65 100644 --- a/helix-term/src/ui/info.rs +++ b/helix-term/src/ui/info.rs @@ -1,8 +1,8 @@ use crate::compositor::{Component, Context}; -use helix_view::graphics::Rect; +use helix_view::graphics::{Margin, Rect}; use helix_view::info::Info; use tui::buffer::Buffer as Surface; -use tui::widgets::{Block, Borders, Widget}; +use tui::widgets::{Block, Borders, Paragraph, Widget}; impl Component for Info { fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { @@ -11,10 +11,11 @@ impl Component for Info { // 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 width = self.width + 2 + 2; // +2 for border, +2 for margin + let height = self.height + 2; // +2 for border let area = viewport.intersection(Rect::new( viewport.width.saturating_sub(width), - viewport.height.saturating_sub(height + 2), + viewport.height.saturating_sub(height + 2), // +2 for statusline width, height, )); @@ -24,15 +25,14 @@ impl Component for Info { .title(self.title.as_str()) .borders(Borders::ALL) .border_style(style); - let inner = block.inner(area); + + let margin = Margin { + vertical: 0, + horizontal: 1, + }; + let inner = block.inner(area).inner(&margin); 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); - } + Paragraph::new(self.text.as_str()).render(inner, surface); } } -- cgit v1.2.3-70-g09d2