ui: Implement fmt::Display for Key

embed
Manos Pitsidianakis 2019-03-30 21:21:17 +02:00
parent a774aaebf6
commit c3adc244d7
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 17 additions and 1 deletions

View File

@ -964,7 +964,7 @@ impl Component for Tabbed {
false,
);
write_string_to_grid(
&format!("{:?}", v),
&format!("{}", v),
grid,
Color::Default,
Color::Default,

View File

@ -70,6 +70,22 @@ pub enum Key {
Paste(String),
}
impl fmt::Display for Key {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Key::*;
match self {
F(n) => write!(f, "F{}", n),
Char('\t') => write!(f, "Tab"),
Char('\n') => write!(f, "Enter"),
Char(c) => write!(f, "{}", c),
Alt(c) => write!(f, "M-{}", c),
Ctrl(c) => write!(f, "C-{}", c),
Paste(_) => write!(f, "Pasted buf"),
a => write!(f, "{}", stringify!(a)),
}
}
}
impl<'a> From<&'a String> for Key {
fn from(v: &'a String) -> Self {
Key::Paste(v.to_string())