Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--helix-term/src/keymap.rs2
-rw-r--r--helix-term/src/ui/info.rs2
-rw-r--r--helix-view/src/info.rs16
3 files changed, 11 insertions, 9 deletions
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index 020ecaf4..2385d460 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -106,7 +106,7 @@ impl KeyTrieNode {
(events.join(", "), desc)
})
.collect();
- Info::new(&self.name, &body)
+ Info::new(self.name.clone(), &body)
}
}
diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs
index 217cee6b..1cac7c86 100644
--- a/helix-term/src/ui/info.rs
+++ b/helix-term/src/ui/info.rs
@@ -24,7 +24,7 @@ impl Component for Info {
surface.clear_with(area, popup_style);
let block = Block::bordered()
- .title(self.title.as_str())
+ .title(self.title.as_ref())
.border_style(popup_style);
let margin = Margin::horizontal(1);
diff --git a/helix-view/src/info.rs b/helix-view/src/info.rs
index ca783fef..7fc43f22 100644
--- a/helix-view/src/info.rs
+++ b/helix-view/src/info.rs
@@ -1,12 +1,12 @@
use crate::register::Registers;
use helix_core::unicode::width::UnicodeWidthStr;
-use std::fmt::Write;
+use std::{borrow::Cow, fmt::Write};
#[derive(Debug)]
/// Info box used in editor. Rendering logic will be in other crate.
pub struct Info {
/// Title shown at top.
- pub title: String,
+ pub title: Cow<'static, str>,
/// Text body, should contain newlines.
pub text: String,
/// Body width.
@@ -16,17 +16,19 @@ pub struct Info {
}
impl Info {
- pub fn new<T, U>(title: &str, body: &[(T, U)]) -> Self
+ pub fn new<T, K, V>(title: T, body: &[(K, V)]) -> Self
where
- T: AsRef<str>,
- U: AsRef<str>,
+ T: Into<Cow<'static, str>>,
+ K: AsRef<str>,
+ V: AsRef<str>,
{
+ let title = title.into();
if body.is_empty() {
return Self {
- title: title.to_string(),
height: 1,
width: title.len() as u16,
text: "".to_string(),
+ title,
};
}
@@ -48,7 +50,7 @@ impl Info {
}
Self {
- title: title.to_string(),
+ title,
width: text.lines().map(|l| l.width()).max().unwrap() as u16,
height: body.len() as u16,
text,