diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-05-26 19:49:16 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-05-26 19:52:43 -0400 |
commit | 3181c6d61b5a71c7e408263e85c4d9b67463aa5e (patch) | |
tree | 42925b1ae6da24d2ccee2d64cd55b4204c449ef1 /src/ui | |
parent | c73ada8cd4bb709c9fdd6d2f4b6c9081d762a659 (diff) |
split up keymaps into different modes
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/views/tui_command_menu.rs | 7 | ||||
-rw-r--r-- | src/ui/widgets/tui_help.rs | 10 |
2 files changed, 8 insertions, 9 deletions
diff --git a/src/ui/views/tui_command_menu.rs b/src/ui/views/tui_command_menu.rs index bc94752..2faf0e2 100644 --- a/src/ui/views/tui_command_menu.rs +++ b/src/ui/views/tui_command_menu.rs @@ -4,7 +4,7 @@ use tui::buffer::Buffer; use tui::layout::Rect; use tui::widgets::{Clear, Widget}; -use crate::config::AppKeyMapping; +use crate::config::KeyMapping; use crate::context::AppContext; use crate::ui::views::TuiView; use crate::ui::widgets::TuiMenu; @@ -15,11 +15,11 @@ const BOTTOM_MARGIN: usize = 1; pub struct TuiCommandMenu<'a> { context: &'a AppContext, - keymap: &'a AppKeyMapping, + keymap: &'a KeyMapping, } impl<'a> TuiCommandMenu<'a> { - pub fn new(context: &'a AppContext, keymap: &'a AppKeyMapping) -> Self { + pub fn new(context: &'a AppContext, keymap: &'a KeyMapping) -> Self { Self { context, keymap } } } @@ -31,7 +31,6 @@ impl<'a> Widget for TuiCommandMenu<'a> { // draw menu let mut display_vec: Vec<String> = self .keymap - .as_ref() .iter() .map(|(k, v)| format!(" {} {}", k.to_string(), v)) .collect(); diff --git a/src/ui/widgets/tui_help.rs b/src/ui/widgets/tui_help.rs index cdec4db..b31c5b3 100644 --- a/src/ui/widgets/tui_help.rs +++ b/src/ui/widgets/tui_help.rs @@ -7,7 +7,7 @@ use tui::layout::{Constraint, Rect}; use tui::style::{Color, Modifier, Style}; use tui::widgets::{Cell, Row, Table, Widget}; -use crate::config::AppKeyMapping; +use crate::config::KeyMapping; use crate::key_command::traits::CommandComment; use crate::key_command::CommandKeybind; @@ -96,7 +96,7 @@ impl<'a> Widget for TuiHelp<'a> { // Translates output from 'get_raw_keymap_table' into format, // readable by TUI table widget pub fn get_keymap_table<'a>( - keymap: &'a AppKeyMapping, + keymap: &'a KeyMapping, search_query: &'a str, sort_by: usize, ) -> Vec<Row<'a>> { @@ -115,17 +115,17 @@ pub fn get_keymap_table<'a>( // This function is needed because we cannot access Row items, which // means that we won't be able to sort binds if we create Rows directly pub fn get_raw_keymap_table<'a>( - keymap: &'a AppKeyMapping, + keymap: &'a KeyMapping, search_query: &'a str, sort_by: usize, ) -> Vec<[String; 3]> { let mut rows = Vec::new(); - for (event, bind) in keymap.as_ref() { + for (event, bind) in keymap.iter() { let key = key_event_to_string(event); let (command, comment) = match bind { CommandKeybind::SimpleKeybind(command) => (format!("{}", command), command.comment()), CommandKeybind::CompositeKeybind(sub_keymap) => { - let mut sub_rows = get_raw_keymap_table(sub_keymap, "", sort_by); + let mut sub_rows = get_raw_keymap_table(&sub_keymap, "", sort_by); for _ in 0..sub_rows.len() { let mut sub_row = sub_rows.pop().unwrap(); sub_row[0] = key.clone() + &sub_row[0]; |