diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-11-02 12:19:21 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-11-02 12:19:21 -0500 |
commit | 0cb2c16b4661762efbe3f8263ebb7837657cfb92 (patch) | |
tree | cfd70ab8c58d4d154dd8b152ac607c42a5f92eff /src/ui | |
parent | 9b6aea79036c40885f352d26e8a2a4892da15306 (diff) |
stop using debug print for termion key
- fix certain commands not showing options
- fix typos
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/widgets/tui_menu.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/ui/widgets/tui_menu.rs b/src/ui/widgets/tui_menu.rs index 85b0a7a..aa5a0d0 100644 --- a/src/ui/widgets/tui_menu.rs +++ b/src/ui/widgets/tui_menu.rs @@ -20,6 +20,34 @@ const BOTTOM_MARGIN: usize = 1; pub struct TuiCommandMenu; +trait ToString { + fn to_string(&self) -> String; +} + +impl ToString for Key { + fn to_string(&self) -> String { + match *self { + Key::Char(c) => format!("{}", c), + Key::Ctrl(c) => format!("ctrl+{}", c), + Key::Left => format!("arrow_left"), + Key::Right => format!("arrow_right"), + Key::Up => format!("arrow_up"), + Key::Down => format!("arrow_down"), + Key::Backspace => format!("backspace"), + Key::Home => format!("home"), + Key::End => format!("end"), + Key::PageUp => format!("page_up"), + Key::PageDown => format!("page_down"), + Key::BackTab => format!("backtab"), + Key::Insert => format!("insert"), + Key::Delete => format!("delete"), + Key::Esc => format!("escape"), + Key::F(i) => format!("f{}", i), + k => format!("{:?}", k), + } + } +} + impl TuiCommandMenu { pub fn new() -> Self { Self {} @@ -49,7 +77,7 @@ impl TuiCommandMenu { let mut display_vec: Vec<String> = map .as_ref() .iter() - .map(|(k, v)| format!(" {:?} {}", k, v)) + .map(|(k, v)| format!(" {} {}", k.to_string(), v)) .collect(); display_vec.sort(); let display_str: Vec<&str> = display_vec.iter().map(|v| v.as_str()).collect(); |