diff --git a/src/keybindings/keybindings.rs b/src/keybindings/keybindings.rs index 0289b976..3049795f 100644 --- a/src/keybindings/keybindings.rs +++ b/src/keybindings/keybindings.rs @@ -6,7 +6,7 @@ use super::{action::Action, KeyCombo}; /// A list of [`keybindings`](KeyCombo) each associated with an [`Action`]. #[derive(Debug, Clone, Deserialize, PartialEq, Eq)] -pub struct Keybindings(Vec<(Action, KeyCombo)>); +pub struct Keybindings(pub(crate) Vec<(Action, KeyCombo)>); impl Keybindings { /// Returns an iterator over the [`Action`]s and [`KeyCombo`]s diff --git a/src/keybindings/tests.rs b/src/keybindings/tests.rs index b6c01be8..a2d4ff8d 100644 --- a/src/keybindings/tests.rs +++ b/src/keybindings/tests.rs @@ -1,5 +1,5 @@ use super::action::{Action, VertDirection}; -use super::{KeyCombos, ModifiedKey}; +use super::{KeyCombos, Keybindings, ModifiedKey}; use crate::opts::Config; use crate::test_utils::init_test_log; @@ -44,3 +44,53 @@ base = [ assert_eq!(key_combos.munch(key), maybe_action); } } + +// TODO(cosmic): Move this to reading from the `inlyne.default.toml` file after a bit of cleanup to +// make things less verbose +// TODO(cosmic): Consider switching the casing away from PascalCase? Maybe keep it inline with the +// rest of the config file and use kebab-case instead? +// TODO(cosmic): Allow for passing a single string for `mod` +const DEFAULTS_TEMPLATE: &str = r#" +[keybindings] +base = [ + # Regular + ["Copy", { key = "c", mod = ["CTRL_OR_CMD"] }], + ["ZoomIn", { key = "=", mod = ["CTRL_OR_CMD"] }], + ["ZoomOut", { key = "-", mod = ["CTRL_OR_CMD"] }], + ["HistoryNext", { key = "Right", mod = ["Alt"] }], + ["HistoryPrevious", { key = "Left", mod = ["Alt"] }], + ["ScrollUp", "Up"], + ["ScrollDown", "Down"], + ["PageUp", "PageUp"], + ["PageDown", "PageDown"], + ["ToTop", "Home"], + ["ToBottom", "End"], + ["Quit", "Escape"], + # Vim-like + ["Copy", "y"], + ["ScrollUp", "k"], + ["ScrollDown", "j"], + ["ToTop", ["g", "g"]], + ["ToBottom", { key = "g", mod = ["Shift"] }], + ["Quit", "q"], + ["Quit", [{ key = "z", mod = ["Shift"] }, { key = "z", mod = ["Shift"] }]], + ["Quit", [{ key = "z", mod = ["Shift"] }, { key = "q", mod = ["Shift"] }]], + ["HistoryNext", ["b", "n"]], + ["HistoryPrevious", ["b", "p"]], +] +"#; + +#[test] +fn defaults() { + let ctrl_or_cmd = if cfg!(target_os = "macos") { + "Os" + } else { + "Ctrl" + }; + let defaults = DEFAULTS_TEMPLATE.replace("CTRL_OR_CMD", ctrl_or_cmd); + let Config { keybindings, .. } = Config::load_from_str(&defaults).unwrap(); + let config_defaults: Keybindings = keybindings.into(); + + let internal_defaults = Keybindings(super::defaults::defaults()); + assert_eq!(config_defaults, internal_defaults); +}