aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/text.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-02-20 05:44:44 +0000
committerBlaž Hrastnik2022-02-20 05:44:44 +0000
commit2af04325d83cd0141400951252574666cffdf1af (patch)
tree5ead25957fa265638d9714e0d7c8568d75261035 /helix-term/src/ui/text.rs
parenta449156702112a1ee1d11ef2f5495067d801deef (diff)
fix: Allow multi-line prompt documentation
Diffstat (limited to 'helix-term/src/ui/text.rs')
-rw-r--r--helix-term/src/ui/text.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/helix-term/src/ui/text.rs b/helix-term/src/ui/text.rs
index caece049..c318052b 100644
--- a/helix-term/src/ui/text.rs
+++ b/helix-term/src/ui/text.rs
@@ -4,7 +4,7 @@ use tui::buffer::Buffer as Surface;
use helix_view::graphics::Rect;
pub struct Text {
- contents: tui::text::Text<'static>,
+ pub(crate) contents: tui::text::Text<'static>,
size: (u16, u16),
viewport: (u16, u16),
}
@@ -49,3 +49,19 @@ impl Component for Text {
Some(self.size)
}
}
+
+pub fn required_size(text: &tui::text::Text, max_text_width: u16) -> (u16, u16) {
+ let mut text_width = 0;
+ let mut height = 0;
+ for content in &text.lines {
+ height += 1;
+ let content_width = content.width() as u16;
+ if content_width > max_text_width {
+ text_width = max_text_width;
+ height += content_width / max_text_width;
+ } else if content_width > text_width {
+ text_width = content_width;
+ }
+ }
+ (text_width, height)
+}