diff options
author | Ivan Tham | 2021-07-03 16:12:02 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-07-04 09:01:59 +0000 |
commit | 916362d3a97ddc1b4a630f7d7ba5ae5dc405c21a (patch) | |
tree | 6ee80ca9764ece107c7fd9f31d492f30da55a295 | |
parent | bbbbfa9bcfb7b46d2ca2c8ac85891b1393bfe401 (diff) |
Info box add horizontal padding
-rw-r--r-- | helix-view/src/info.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/helix-view/src/info.rs b/helix-view/src/info.rs index 92c10351..f3df50fe 100644 --- a/helix-view/src/info.rs +++ b/helix-view/src/info.rs @@ -17,6 +17,7 @@ pub struct Info { impl Info { pub fn key(title: &'static str, body: Vec<(&[KeyEvent], &'static str)>) -> Info { + let (lpad, mpad, rpad) = (1, 2, 1); let keymaps_width: u16 = body .iter() .map(|r| r.0.iter().map(|e| e.width() as u16 + 2).sum::<u16>() - 2) @@ -28,18 +29,23 @@ impl Info { for (keyevents, desc) in body { let keyevent = keyevents[0]; let mut left = keymaps_width - keyevent.width() as u16; + for _ in 0..lpad { + text.push(' '); + } write!(text, "{}", keyevent).ok(); for keyevent in &keyevents[1..] { write!(text, ", {}", keyevent).ok(); left -= 2 + keyevent.width() as u16; } - for _ in 0..left { + for _ in 0..left + mpad { text.push(' '); } - if keymaps_width + 2 + (desc.width() as u16) > width { - width = keymaps_width + 2 + desc.width() as u16; + let desc = desc.trim(); + let w = lpad + keymaps_width + mpad + (desc.width() as u16) + rpad; + if w > width { + width = w; } - writeln!(text, " {}", &desc).ok(); + writeln!(text, "{}", desc).ok(); } Info { title, |