summaryrefslogtreecommitdiff
path: root/helix-view/src/info.rs
diff options
context:
space:
mode:
authorIvan Tham2021-07-02 01:46:28 +0000
committerBlaž Hrastnik2021-07-04 09:01:59 +0000
commit5977b07e197cc6ef9051dd34a28b9fe28e01e966 (patch)
treee14f86efd2d8c44d87f7de25f69ef735b0aaaf92 /helix-view/src/info.rs
parent64f83dfcbd3e093a31b2ef6bd787161ea8904583 (diff)
Reduce calculation and improve pattern in infobox
- switch to use static OnceCell to calculate Info once - pass Vec<(&[KeyEvent], &str)> rather than Vec<(Vec<KeyEvent>, &str)> - expr -> tt to allow using | as separator, make it more like match
Diffstat (limited to 'helix-view/src/info.rs')
-rw-r--r--helix-view/src/info.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/helix-view/src/info.rs b/helix-view/src/info.rs
index 0eaab783..92c10351 100644
--- a/helix-view/src/info.rs
+++ b/helix-view/src/info.rs
@@ -16,7 +16,7 @@ pub struct Info {
}
impl Info {
- pub fn key(title: &'static str, body: Vec<(Vec<KeyEvent>, &'static str)>) -> Info {
+ pub fn key(title: &'static str, body: Vec<(&[KeyEvent], &'static str)>) -> Info {
let keymaps_width: u16 = body
.iter()
.map(|r| r.0.iter().map(|e| e.width() as u16 + 2).sum::<u16>() - 2)
@@ -25,11 +25,11 @@ impl Info {
let mut text = String::new();
let mut width = 0;
let height = body.len() as u16;
- for (mut keyevents, desc) in body {
- let keyevent = keyevents.remove(0);
+ for (keyevents, desc) in body {
+ let keyevent = keyevents[0];
let mut left = keymaps_width - keyevent.width() as u16;
write!(text, "{}", keyevent).ok();
- for keyevent in keyevents {
+ for keyevent in &keyevents[1..] {
write!(text, ", {}", keyevent).ok();
left -= 2 + keyevent.width() as u16;
}