@@ -4,13 +4,23 @@ use tui::buffer::Buffer as Surface;
4use helix_view::graphics::Rect;
4use helix_view::graphics::Rect;
6pub struct Text {
6pub struct Text {
7− contents: String,
7+ contents: tui::text::Text<'static>,
8 size: (u16, u16),
8 size: (u16, u16),
9 viewport: (u16, u16),
9 viewport: (u16, u16),
12impl Text {
12impl Text {
13 pub fn new(contents: String) -> Self {
13 pub fn new(contents: String) -> Self {
15+ contents: tui::text::Text::from(contents),
22+impl From<tui::text::Text<'static>> for Text {
23+ fn from(contents: tui::text::Text<'static>) -> Self {
16 size: (0, 0),
26 size: (0, 0),
@@ -18,12 +28,12 @@ impl Text {
21impl Component for Text {
32impl Component for Text {
22 fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
33 fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
23 use tui::widgets::{Paragraph, Widget, Wrap};
34 use tui::widgets::{Paragraph, Widget, Wrap};
24− let contents = tui::text::Text::from(self.contents.clone());
26− let par = Paragraph::new(contents).wrap(Wrap { trim: false });
36+ let par = Paragraph::new(self.contents.clone()).wrap(Wrap { trim: false });
27 // .scroll(x, y) offsets
37 // .scroll(x, y) offsets
29 par.render(area, surface);
39 par.render(area, surface);
@@ -31,9 +41,8 @@ impl Component for Text {
32 fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
42 fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
33 if viewport != self.viewport {
43 if viewport != self.viewport {
34− let contents = tui::text::Text::from(self.contents.clone());
35− let width = std::cmp::min(contents.width() as u16, viewport.0);
44+ let width = std::cmp::min(self.contents.width() as u16, viewport.0);
36− let height = std::cmp::min(contents.height() as u16, viewport.1);
45+ let height = std::cmp::min(self.contents.height() as u16, viewport.1);
37 self.size = (width, height);
46 self.size = (width, height);
38 self.viewport = viewport;
47 self.viewport = viewport;