diff options
author | Tim Oram <dev@mitmaro.ca> | 2019-07-22 22:20:09 -0230 |
---|---|---|
committer | Tim Oram <dev@mitmaro.ca> | 2019-07-22 23:32:28 -0230 |
commit | 0d565b5cae7b8aed4578e266c3c3375772d75564 (patch) | |
tree | 27ca0814d8cbaa7d217bc2c3cbdda61ff027e60b | |
parent | b8dfdaaf0a86567598e0a9f38d285b8e3a4edcd4 (diff) |
Finish adding keybindings
A few key bindings were incomplete and the help did not respect the
custom keybindings.
-rw-r--r-- | README.md | 98 | ||||
-rw-r--r-- | src/config.rs | 6 | ||||
-rw-r--r-- | src/help/utils.rs | 131 | ||||
-rw-r--r-- | src/input/input_handler.rs | 43 | ||||
-rw-r--r-- | src/input/mod.rs | 2 | ||||
-rw-r--r-- | src/input/utils.rs | 15 | ||||
-rw-r--r-- | src/list/utils.rs | 98 |
7 files changed, 255 insertions, 138 deletions
@@ -92,56 +92,60 @@ git config --global interactive-rebase-tool.foregroundColor black #### Options -| Key | Default | Type | Description | -| -------------------------- | ------- | ------ | ----------- | -| `autoSelectNext` | false | bool | If true, auto select the next line after action modification | -| `breakColor` | white | Color | Color used for the break action | -| `diffAddColor` | green | Color | Color used for lines and files added in a diff | -| `diffChangeColor` | yellow | Color | Color used for lines and files changed in a diff | -| `diffRemoveColor` | red | Color | Color used for lines and files removed in a diff | -| `dropColor` | red | Color | Color used for the drop action | -| `editColor` | blue | Color | Color used for the edit action | -| `errorColor` | red | Color | Color used for showing error messages | -| `fixupColor` | magenta | Color | Color used for the fixup action | -| `foregroundColor` | white | Color | Color used for most text and the UI | -| `indicatorColor` | cyan | Color | Color used for text the indicates or needs to standout | -| `inputAbort` | q | String | Key for abort rebase with prompt | -| `inputActionBreak` | b | String | Key for setting action to rebase | -| `inputActionDrop` | d | String | Key for setting action to drop | -| `inputActionEdit` | e | String | Key for setting action to edit | -| `inputActionFixup` | f | String | Key for setting action to fixup | -| `inputActionPick` | p | String | Key for setting action to pick | -| `inputActionReword` | r | String | Key for setting action to reword | -| `inputActionSquash` | s | String | Key for setting action to squash | -| `inputConfirmNo` | n | String | Key for rejecting a confirmation | -| `inputConfirmYes` | y | String | Key for confirming a confirmation | -| `inputEdit` | E | String | Key for entering edit mode | -| `inputForceAbort` | Q | String | Key for forcing an abort of the rebase | -| `inputForceRebase` | W | String | Key for forcing a rebase | -| `inputHelp` | ? | String | Key for showing the help | -| `inputMoveDown` | Down | String | Key for moving the selected line(s) down | -| `inputMoveLeft` | Left | String | Key for moving the selected line(s) down | -| `inputMoveRight` | Right | String | Key for moving the selected line(s) down | -| `inputMoveSelectionDown` | j | String | Key for moving the selected line(s) down | -| `inputMoveSelectionUp` | k | String | Key for moving the selected line(s) up | -| `inputMoveUp` | Up | String | Key for moving the selected line(s) up | -| `inputOpenInExternalEditor`| ! | String | Key for opening the external editor | -| `inputRebase` | w | String | Key for rebasing with confirmation | -| `inputShowCommit` | c | String | Key for showing the selected commit | -| `inputToggleVisualMode` | v | String | Key for toggling visual mode | -| `pickColor` | green | Color | Color used for the pick action | -| `rewordColor` | yellow | Color | Color used for the reword action | -| `squashColor` | cyan | Color | Color used for the squash action | -| `verticalSpacingCharacter` | ~ | String | Vertical spacing character. Can be set to an empty string. | +| Key | Default | Type | Description | +| -------------------------- | -------- | ------ | ----------- | +| `autoSelectNext` | false | bool | If true, auto select the next line after action modification | +| `breakColor` | white | Color | Color used for the break action | +| `diffAddColor` | green | Color | Color used for lines and files added in a diff | +| `diffChangeColor` | yellow | Color | Color used for lines and files changed in a diff | +| `diffRemoveColor` | red | Color | Color used for lines and files removed in a diff | +| `dropColor` | red | Color | Color used for the drop action | +| `editColor` | blue | Color | Color used for the edit action | +| `errorColor` | red | Color | Color used for showing error messages | +| `fixupColor` | magenta | Color | Color used for the fixup action | +| `foregroundColor` | white | Color | Color used for most text and the UI | +| `indicatorColor` | cyan | Color | Color used for text the indicates or needs to standout | +| `inputAbort` | q | String | Key for abort rebase with prompt | +| `inputActionBreak` | b | String | Key for setting action to rebase | +| `inputActionDrop` | d | String | Key for setting action to drop | +| `inputActionEdit` | e | String | Key for setting action to edit | +| `inputActionFixup` | f | String | Key for setting action to fixup | +| `inputActionPick` | p | String | Key for setting action to pick | +| `inputActionReword` | r | String | Key for setting action to reword | +| `inputActionSquash` | s | String | Key for setting action to squash | +| `inputConfirmNo` | n | String | Key for rejecting a confirmation | +| `inputConfirmYes` | y | String | Key for confirming a confirmation | +| `inputEdit` | E | String | Key for entering edit mode | +| `inputForceAbort` | Q | String | Key for forcing an abort of the rebase | +| `inputForceRebase` | W | String | Key for forcing a rebase | +| `inputHelp` | ? | String | Key for showing the help | +| `inputMoveDownStep` | PageDown | String | Key for moving the cursor down by a large step | +| `inputMoveDown` | Down | String | Key for moving the cursor down | +| `inputMoveLeft` | Left | String | Key for moving the cursor left | +| `inputMoveRight` | Right | String | Key for moving the cursor right | +| `inputMoveSelectionDown` | j | String | Key for moving the selected line(s) down | +| `inputMoveSelectionUp` | k | String | Key for moving the selected line(s) up | +| `inputMoveUp` | Up | String | Key for moving the cursor up | +| `inputMoveUpStep` | PageUp | String | Key for moving the cursor up by a large step| +| `inputOpenInExternalEditor`| ! | String | Key for opening the external editor | +| `inputRebase` | w | String | Key for rebasing with confirmation | +| `inputShowCommit` | c | String | Key for showing the selected commit | +| `inputToggleVisualMode` | v | String | Key for toggling visual mode | +| `pickColor` | green | Color | Color used for the pick action | +| `rewordColor` | yellow | Color | Color used for the reword action | +| `squashColor` | cyan | Color | Color used for the squash action | +| `verticalSpacingCharacter` | ~ | String | Vertical spacing character. Can be set to an empty string. | #### Special Keys -| Key | Description | -| ------- | ----------- | -| `Down` | Down arrow key | -| `Left` | Left arrow key | -| `Right` | Right arrow key | -| `Up` | Up arrow key | +| Key | Description | +| ---------- | ----------- | +| `PageDown` | Page Down key | +| `Down` | Down arrow key | +| `Left` | Left arrow key | +| `Right` | Right arrow key | +| `Up` | Up arrow key | +| `PageUp` | Page Up key | #### Valid Color Values diff --git a/src/config.rs b/src/config.rs index 20918a7..328bbf7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,11 +33,13 @@ pub struct Config { pub input_force_rebase: String, pub input_help: String, pub input_move_down: String, + pub input_move_down_step: String, pub input_move_left: String, pub input_move_right: String, pub input_move_selection_down: String, pub input_move_selection_up: String, pub input_move_up: String, + pub input_move_up_step: String, pub input_open_in_external_editor: String, pub input_rebase: String, pub input_show_commit: String, @@ -56,6 +58,8 @@ fn get_input(config: &git2::Config, name: &str, default: &str) -> Result<String, "right" => Ok(String::from("Right")), "down" => Ok(String::from("Down")), "up" => Ok(String::from("Up")), + "pageup" => Ok(String::from("PageUp")), + "pagedown" => Ok(String::from("PageDown")), _ => { if value.len() > 1 { return Err(format!( @@ -153,6 +157,8 @@ impl Config { input_move_down: get_input(&git_config, "interactive-rebase-tool.inputMoveDown", "Down")?, input_move_left: get_input(&git_config, "interactive-rebase-tool.inputMoveLeft", "Left")?, input_move_right: get_input(&git_config, "interactive-rebase-tool.inputMoveRight", "Right")?, + input_move_up_step: get_input(&git_config, "interactive-rebase-tool.inputMoveStepUp", "PageUp")?, + input_move_down_step: get_input(&git_config, "interactive-rebase-tool.inputMoveStepDown", "PageDown")?, input_move_selection_down: get_input(&git_config, "interactive-rebase-tool.inputMoveSelectionDown", "j")?, input_move_selection_up: get_input(&git_config, "interactive-rebase-tool.inputMoveSelectionUp", "k")?, input_move_up: get_input(&git_config, "interactive-rebase-tool.inputMoveUp", "Up")?, diff --git a/src/help/utils.rs b/src/help/utils.rs index 00cef87..0aa7a53 100644 --- a/src/help/utils.rs +++ b/src/help/utils.rs @@ -1,51 +1,102 @@ use crate::Config; use unicode_segmentation::UnicodeSegmentation; +fn get_input_short_name(input: &str) -> String { + if input == "PageUp" { + String::from("PgUp") + } + else if input == "PageDown" { + String::from("PgDn") + } + else if input == "Resize" { + String::from("Rsze") + } + else if input == "Other" { + String::from("Oth") + } + else { + String::from(input) + } +} + pub fn get_list_normal_mode_help_lines(config: &Config) -> [(String, &str); 21] { [ - (String::from("Up"), "Move selection up"), - (String::from("Down"), "Move selection down"), - (String::from("PgUp"), "Move selection up 5 lines"), - (String::from("PgDn"), "Move selection down 5 lines"), - (config.input_abort.to_string(), "Abort interactive rebase"), + (get_input_short_name(config.input_move_up.as_str()), "Move selection up"), ( - config.input_force_abort.to_string(), + get_input_short_name(config.input_move_down.as_str()), + "Move selection down", + ), + ( + get_input_short_name(config.input_move_up_step.as_str()), + "Move selection up 5 lines", + ), + ( + get_input_short_name(config.input_move_down_step.as_str()), + "Move selection down 5 lines", + ), + ( + get_input_short_name(config.input_abort.as_str()), + "Abort interactive rebase", + ), + ( + get_input_short_name(config.input_force_abort.as_str()), "Immediately abort interactive rebase", ), - (config.input_rebase.to_string(), "Write interactive rebase file"), ( - config.input_force_rebase.to_string(), + get_input_short_name(config.input_rebase.as_str()), + "Write interactive rebase file", + ), + ( + get_input_short_name(config.input_force_rebase.as_str()), "Immediately write interactive rebase file", ), - (config.input_help.to_string(), "Show help"), - (config.input_show_commit.to_string(), "Show commit information"), + (get_input_short_name(config.input_help.as_str()), "Show help"), + ( + get_input_short_name(config.input_show_commit.as_str()), + "Show commit information", + ), ( - config.input_move_selection_down.to_string(), + get_input_short_name(config.input_move_selection_down.as_str()), "Move selected commit down", ), - (config.input_move_selection_up.to_string(), "Move selected commit up"), - (config.input_action_break.to_string(), "Toggle break action"), - (config.input_action_pick.to_string(), "Set selected commit to be picked"), ( - config.input_action_reword.to_string(), + get_input_short_name(config.input_move_selection_up.as_str()), + "Move selected commit up", + ), + ( + get_input_short_name(config.input_action_break.as_str()), + "Toggle break action", + ), + ( + get_input_short_name(config.input_action_pick.as_str()), + "Set selected commit to be picked", + ), + ( + get_input_short_name(config.input_action_reword.as_str()), "Set selected commit to be reworded", ), - (config.input_action_edit.to_string(), "Set selected commit to be edited"), ( - config.input_action_squash.to_string(), + get_input_short_name(config.input_action_edit.as_str()), + "Set selected commit to be edited", + ), + ( + get_input_short_name(config.input_action_squash.as_str()), "Set selected commit to be squashed", ), ( - config.input_action_fixup.to_string(), + get_input_short_name(config.input_action_fixup.as_str()), "Set selected commit to be fixed-up", ), ( - config.input_action_drop.to_string(), + get_input_short_name(config.input_action_drop.as_str()), "Set selected commit to be dropped", ), - (config.input_edit.to_string(), "Edit an exec action's command"), ( - config.input_open_in_external_editor.to_string(), + get_input_short_name(config.input_edit.as_str()), + "Edit an exec action's command", + ), + ( + get_input_short_name(config.input_open_in_external_editor.as_str()), "Open the todo file in the default editor", ), ] @@ -53,38 +104,50 @@ pub fn get_list_normal_mode_help_lines(config: &Config) -> [(String, &str); 21] pub fn get_list_visual_mode_help_lines(config: &Config) -> [(String, &str); 13] { [ - (String::from("Up"), "Move selection up"), - (String::from("Down"), "Move selection down"), - (String::from("PgUp"), "Move selection up 5 lines"), - (String::from("PgDn"), "Move selection down 5 lines"), - (config.input_help.to_string(), "Show help"), + (get_input_short_name(config.input_move_up.as_str()), "Move selection up"), + ( + get_input_short_name(config.input_move_down.as_str()), + "Move selection down", + ), + ( + get_input_short_name(config.input_move_up_step.as_str()), + "Move selection up 5 lines", + ), ( - config.input_move_selection_down.to_string(), + get_input_short_name(config.input_move_down_step.as_str()), + "Move selection down 5 lines", + ), + (get_input_short_name(config.input_help.as_str()), "Show help"), + ( + get_input_short_name(config.input_move_selection_down.as_str()), "Move selected commits down", ), - (config.input_move_selection_up.to_string(), "Move selected commits up"), ( - config.input_action_pick.to_string(), + get_input_short_name(config.input_move_selection_up.as_str()), + "Move selected commits up", + ), + ( + get_input_short_name(config.input_action_pick.as_str()), "Set selected commits to be picked", ), ( - config.input_action_reword.to_string(), + get_input_short_name(config.input_action_reword.as_str()), "Set selected commits to be reworded", ), ( - config.input_action_edit.to_string(), + get_input_short_name(config.input_action_edit.as_str()), "Set selected commits to be edited", ), ( - config.input_action_squash.to_string(), + get_input_short_name(config.input_action_squash.as_str()), "Set selected commits to be squashed", ), ( - config.input_action_fixup.to_string(), + get_input_short_name(config.input_action_fixup.as_str()), "Set selected commits to be fixed-up", ), ( - config.input_action_drop.to_string(), + get_input_short_name(config.input_action_drop.as_str()), "Set selected commits to be dropped", ), ] diff --git a/src/input/input_handler.rs b/src/input/input_handler.rs index e12b9db..56716b6 100644 --- a/src/input/input_handler.rs +++ b/src/input/input_handler.rs @@ -1,3 +1,4 @@ +use crate::input::utils::curses_input_to_string; use crate::input::Input; use crate::window::Window; use crate::Config; @@ -20,31 +21,15 @@ impl<'i> InputHandler<'i> { } pub fn get_input(&self) -> Input { - // ignore None's, since they are not really valid input - let c = loop { - let c = self.window.getch(); - if c.is_some() { - break c.unwrap(); - } - }; + let c = self.get_next_input(); - let input = match c { - PancursesInput::Character(c) => c.to_string(), - PancursesInput::KeyLeft => String::from("Left"), - PancursesInput::KeyRight => String::from("Right"), - PancursesInput::KeyDown => String::from("Down"), - PancursesInput::KeyUp => String::from("Up"), - PancursesInput::KeyPPage => String::from("PageUp"), - PancursesInput::KeyNPage => String::from("PageDown"), - PancursesInput::KeyResize => String::from("Resize"), - _ => String::from("Other"), - }; + let input = curses_input_to_string(c); match input.as_str() { i if i == self.config.input_abort.as_str() => Input::Abort, i if i == self.config.input_action_break.as_str() => Input::ActionBreak, i if i == self.config.input_action_drop.as_str() => Input::ActionDrop, - i if i == self.config.input_action_drop.as_str() => Input::Help, + i if i == self.config.input_help.as_str() => Input::Help, i if i == self.config.input_action_edit.as_str() => Input::ActionEdit, i if i == self.config.input_action_fixup.as_str() => Input::ActionFixup, i if i == self.config.input_action_pick.as_str() => Input::ActionPick, @@ -63,8 +48,8 @@ impl<'i> InputHandler<'i> { i if i == self.config.input_rebase.as_str() => Input::Rebase, i if i == self.config.input_show_commit.as_str() => Input::ShowCommit, i if i == self.config.input_toggle_visual_mode.as_str() => Input::ToggleVisualMode, - "PageUp" => Input::MoveCursorPageUp, - "PageDown" => Input::MoveCursorPageDown, + i if i == self.config.input_move_up_step.as_str() => Input::MoveCursorPageUp, + i if i == self.config.input_move_down_step.as_str() => Input::MoveCursorPageDown, "Resize" => Input::Resize, _ => Input::Other, } @@ -87,12 +72,7 @@ impl<'i> InputHandler<'i> { pub fn get_character(&self) -> Input { loop { - let c = loop { - let c = self.window.getch(); - if c.is_some() { - break c.unwrap(); - } - }; + let c = self.get_next_input(); match c { PancursesInput::Character(c) if c == '\n' => break Input::Enter, @@ -107,4 +87,13 @@ impl<'i> InputHandler<'i> { }; } } + + fn get_next_input(&self) -> PancursesInput { + loop { + let c = self.window.getch(); + if c.is_some() { + break c.unwrap(); + } + } + } } diff --git a/src/input/mod.rs b/src/input/mod.rs index 4f97059..63e76c4 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1,6 +1,8 @@ #[allow(clippy::module_inception)] mod input; mod input_handler; +mod utils; pub use self::input::Input; pub use self::input_handler::InputHandler; +pub use self::utils::curses_input_to_string; diff --git a/src/input/utils.rs b/src/input/utils.rs new file mode 100644 index 0000000..05e2747 --- /dev/null +++ b/src/input/utils.rs @@ -0,0 +1,15 @@ +use pancurses::Input; + +pub fn curses_input_to_string(input: Input) -> String { + match input { + Input::Character(c) => c.to_string(), + Input::KeyLeft => String::from("Left"), + Input::KeyRight => String::from("Right"), + Input::KeyDown => String::from("Down"), + Input::KeyUp => String::from("Up"), + Input::KeyPPage => String::from("PageUp"), + Input::KeyNPage => String::from("PageDown"), + Input::KeyResize => String::from("Resize"), + _ => String::from("Other"), + } +} diff --git a/src/list/utils.rs b/src/list/utils.rs index 1fd19c0..656f016 100644 --- a/src/list/utils.rs +++ b/src/list/utils.rs @@ -2,6 +2,36 @@ use crate::action::Action; use crate::window::WindowColor; use crate::Config; +fn get_input_short_name(input: &str) -> String { + if input == "Left" { + String::from("lf") + } + else if input == "Right" { + String::from("rt") + } + else if input == "Down" { + String::from("dn") + } + else if input == "Up" { + String::from("up") + } + else if input == "PageUp" { + String::from("pup") + } + else if input == "PageDown" { + String::from("pdn") + } + else if input == "Resize" { + String::from("rz") + } + else if input == "Other" { + String::from("ot") + } + else { + String::from(input) + } +} + pub fn get_action_color(action: Action) -> WindowColor { match action { Action::Break => WindowColor::ActionBreak, @@ -17,7 +47,9 @@ pub fn get_action_color(action: Action) -> WindowColor { pub fn get_normal_footer_full(config: &Config) -> String { format!( - " up, down, {}/{}, {}/{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}", + " {}, {}, {}/{}, {}/{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}", + config.input_move_up, + config.input_move_down, config.input_abort, config.input_force_abort, config.input_rebase, @@ -40,7 +72,9 @@ pub fn get_normal_footer_full(config: &Config) -> String { pub fn get_visual_footer_full(config: &Config) -> String { format!( - " up, down, {}, {}, {}, {}, {}, {}, {}, {}, {}", + " {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}", + config.input_move_up, + config.input_move_down, config.input_move_selection_down, config.input_move_selection_up, config.input_action_pick, @@ -55,38 +89,42 @@ pub fn get_visual_footer_full(config: &Config) -> String { pub fn get_normal_footer_compact(config: &Config) -> String { format!( - "up,dn,{}/{},{}/{},{},{},{},{},{},{},{},{},{},{},{},{},{}", - config.input_abort, - config.input_force_abort, - config.input_rebase, - config.input_force_rebase, - config.input_show_commit, - config.input_move_selection_down, - config.input_move_selection_up, - config.input_action_break, - config.input_action_pick, - config.input_action_reword, - config.input_action_edit, - config.input_action_squash, - config.input_action_fixup, - config.input_action_drop, - config.input_edit, - config.input_open_in_external_editor, - config.input_help, + "{},{},{}/{},{}/{},{},{},{},{},{},{},{},{},{},{},{},{},{}", + get_input_short_name(config.input_move_up.as_str()), + get_input_short_name(config.input_move_down.as_str()), + get_input_short_name(config.input_abort.as_str()), + get_input_short_name(config.input_force_abort.as_str()), + get_input_short_name(config.input_rebase.as_str()), + get_input_short_name(config.input_force_rebase.as_str()), + get_input_short_name(config.input_show_commit.as_str()), + get_input_short_name(config.input_move_selection_down.as_str()), + get_input_short_name(config.input_move_selection_up.as_str()), + get_input_short_name(config.input_action_break.as_str()), + get_input_short_name(config.input_action_pick.as_str()), + get_input_short_name(config.input_action_reword.as_str()), + get_input_short_name(config.input_action_edit.as_str()), + get_input_short_name(config.input_action_squash.as_str()), + get_input_short_name(config.input_action_fixup.as_str()), + get_input_short_name(config.input_action_drop.as_str()), + get_input_short_name(config.input_edit.as_str()), + get_input_short_name(config.input_open_in_external_editor.as_str()), + get_input_short_name(config.input_help.as_str()), ) } pub fn get_visual_footer_compact(config: &Config) -> String { format!( - "up,dn,{},{},{},{},{},{},{},{},{}", - config.input_move_selection_down, - config.input_move_selection_up, - config.input_action_pick, - config.input_action_reword, - config.input_action_edit, - config.input_action_squash, - config.input_action_fixup, - config.input_action_drop, - config.input_help, + "{},{},{},{},{},{},{},{},{},{},{}", + get_input_short_name(config.input_move_up.as_str()), + get_input_short_name(config.input_move_down.as_str()), + get_input_short_name(config.input_move_selection_down.as_str()), + get_input_short_name(config.input_move_selection_up.as_str()), + get_input_short_name(config.input_action_pick.as_str()), + get_input_short_name(config.input_action_reword.as_str()), + get_input_short_name(config.input_action_edit.as_str()), + get_input_short_name(config.input_action_squash.as_str()), + get_input_short_name(config.input_action_fixup.as_str()), + get_input_short_name(config.input_action_drop.as_str()), + get_input_short_name(config.input_help.as_str()), ) } |