|
|
@ -16,7 +16,11 @@ pub struct Info {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Info {
|
|
|
|
impl Info {
|
|
|
|
pub fn new(title: &str, body: Vec<(String, String)>) -> Self {
|
|
|
|
pub fn new<T, U>(title: &str, body: &[(T, U)]) -> Self
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
T: AsRef<str>,
|
|
|
|
|
|
|
|
U: AsRef<str>,
|
|
|
|
|
|
|
|
{
|
|
|
|
if body.is_empty() {
|
|
|
|
if body.is_empty() {
|
|
|
|
return Self {
|
|
|
|
return Self {
|
|
|
|
title: title.to_string(),
|
|
|
|
title: title.to_string(),
|
|
|
@ -26,11 +30,21 @@ impl Info {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let item_width = body.iter().map(|(item, _)| item.width()).max().unwrap();
|
|
|
|
let item_width = body
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|(item, _)| item.as_ref().width())
|
|
|
|
|
|
|
|
.max()
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
let mut text = String::new();
|
|
|
|
let mut text = String::new();
|
|
|
|
|
|
|
|
|
|
|
|
for (item, desc) in &body {
|
|
|
|
for (item, desc) in body {
|
|
|
|
let _ = writeln!(text, "{:width$} {}", item, desc, width = item_width);
|
|
|
|
let _ = writeln!(
|
|
|
|
|
|
|
|
text,
|
|
|
|
|
|
|
|
"{:width$} {}",
|
|
|
|
|
|
|
|
item.as_ref(),
|
|
|
|
|
|
|
|
desc.as_ref(),
|
|
|
|
|
|
|
|
width = item_width
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
@ -42,19 +56,19 @@ impl Info {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
|
|
|
|
pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
|
|
|
|
let body = body
|
|
|
|
let body: Vec<_> = body
|
|
|
|
.into_iter()
|
|
|
|
.into_iter()
|
|
|
|
.map(|(desc, events)| {
|
|
|
|
.map(|(desc, events)| {
|
|
|
|
let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
|
|
|
|
let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
|
|
|
|
(events.join(", "), desc.to_string())
|
|
|
|
(events.join(", "), desc)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
|
|
Self::new(title, body)
|
|
|
|
Self::new(title, &body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn from_registers(registers: &Registers) -> Self {
|
|
|
|
pub fn from_registers(registers: &Registers) -> Self {
|
|
|
|
let body = registers
|
|
|
|
let body: Vec<_> = registers
|
|
|
|
.inner()
|
|
|
|
.inner()
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.map(|(ch, reg)| {
|
|
|
|
.map(|(ch, reg)| {
|
|
|
@ -62,13 +76,12 @@ impl Info {
|
|
|
|
.read()
|
|
|
|
.read()
|
|
|
|
.get(0)
|
|
|
|
.get(0)
|
|
|
|
.and_then(|s| s.lines().next())
|
|
|
|
.and_then(|s| s.lines().next())
|
|
|
|
.map(String::from)
|
|
|
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
.unwrap_or_default();
|
|
|
|
(ch.to_string(), content)
|
|
|
|
(ch.to_string(), content)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
|
|
let mut infobox = Self::new("Registers", body);
|
|
|
|
let mut infobox = Self::new("Registers", &body);
|
|
|
|
infobox.width = 30; // copied content could be very long
|
|
|
|
infobox.width = 30; // copied content could be very long
|
|
|
|
infobox
|
|
|
|
infobox
|
|
|
|
}
|
|
|
|
}
|
|
|
|