|
|
@ -17,6 +17,7 @@ pub struct Info {
|
|
|
|
|
|
|
|
|
|
|
|
impl Info {
|
|
|
|
impl Info {
|
|
|
|
pub fn key(title: &'static str, body: Vec<(&[KeyEvent], &'static str)>) -> 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
|
|
|
|
let keymaps_width: u16 = body
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.map(|r| r.0.iter().map(|e| e.width() as u16 + 2).sum::<u16>() - 2)
|
|
|
|
.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 {
|
|
|
|
for (keyevents, desc) in body {
|
|
|
|
let keyevent = keyevents[0];
|
|
|
|
let keyevent = keyevents[0];
|
|
|
|
let mut left = keymaps_width - keyevent.width() as u16;
|
|
|
|
let mut left = keymaps_width - keyevent.width() as u16;
|
|
|
|
|
|
|
|
for _ in 0..lpad {
|
|
|
|
|
|
|
|
text.push(' ');
|
|
|
|
|
|
|
|
}
|
|
|
|
write!(text, "{}", keyevent).ok();
|
|
|
|
write!(text, "{}", keyevent).ok();
|
|
|
|
for keyevent in &keyevents[1..] {
|
|
|
|
for keyevent in &keyevents[1..] {
|
|
|
|
write!(text, ", {}", keyevent).ok();
|
|
|
|
write!(text, ", {}", keyevent).ok();
|
|
|
|
left -= 2 + keyevent.width() as u16;
|
|
|
|
left -= 2 + keyevent.width() as u16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _ in 0..left {
|
|
|
|
for _ in 0..left + mpad {
|
|
|
|
text.push(' ');
|
|
|
|
text.push(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if keymaps_width + 2 + (desc.width() as u16) > width {
|
|
|
|
let desc = desc.trim();
|
|
|
|
width = keymaps_width + 2 + desc.width() as u16;
|
|
|
|
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 {
|
|
|
|
Info {
|
|
|
|
title,
|
|
|
|
title,
|
|
|
|