1 use crate::compositor::{Component, Context}; 2 use helix_view::graphics::{Margin, Rect}; 3 use helix_view::info::Info; 4 use tui::buffer::Buffer as Surface; 5 use tui::widgets::{Block, Borders, Paragraph, Widget}; 6 7 impl Component for Info { render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context)8 fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { 9 let get_theme = |style, fallback| { 10 let theme = &cx.editor.theme; 11 theme.try_get(style).unwrap_or_else(|| theme.get(fallback)) 12 }; 13 let text_style = get_theme("ui.info.text", "ui.text"); 14 let popup_style = text_style.patch(get_theme("ui.info", "ui.popup")); 15 16 // Calculate the area of the terminal to modify. Because we want to 17 // render at the bottom right, we use the viewport's width and height 18 // which evaluate to the most bottom right coordinate. 19 let width = self.width + 2 + 2; // +2 for border, +2 for margin 20 let height = self.height + 2; // +2 for border 21 let area = viewport.intersection(Rect::new( 22 viewport.width.saturating_sub(width), 23 viewport.height.saturating_sub(height + 2), // +2 for statusline 24 width, 25 height, 26 )); 27 surface.clear_with(area, popup_style); 28 29 let block = Block::default() 30 .title(self.title.as_str()) 31 .borders(Borders::ALL) 32 .border_style(popup_style); 33 34 let margin = Margin { 35 vertical: 0, 36 horizontal: 1, 37 }; 38 let inner = block.inner(area).inner(&margin); 39 block.render(area, surface); 40 41 Paragraph::new(self.text.as_str()) 42 .style(text_style) 43 .render(inner, surface); 44 } 45 } 46