diff options
author | Jan Hrastnik | 2021-06-19 12:51:53 +0000 |
---|---|---|
committer | Jan Hrastnik | 2021-06-19 12:51:53 +0000 |
commit | cdd9347457f0608346894cd0aab35b412cb59a7b (patch) | |
tree | 468078c37311cb1c7f9e7d4bd8a03c493d25e669 /helix-term/src/config.rs | |
parent | 97323dc2f90f81afc82bd929d111abda540bebe5 (diff) | |
parent | 2cbec2b0470d0759578929b224c445b69617b6b6 (diff) |
Merge remote-tracking branch 'origin/master' into line_ending_detection
Diffstat (limited to 'helix-term/src/config.rs')
-rw-r--r-- | helix-term/src/config.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs new file mode 100644 index 00000000..9c962299 --- /dev/null +++ b/helix-term/src/config.rs @@ -0,0 +1,63 @@ +use serde::Deserialize; + +use crate::commands::Command; +use crate::keymap::Keymaps; + +#[derive(Debug, PartialEq, Deserialize)] +pub struct GlobalConfig { + pub lsp_progress: bool, +} + +impl Default for GlobalConfig { + fn default() -> Self { + Self { lsp_progress: true } + } +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +#[serde(default)] +pub struct Config { + pub global: GlobalConfig, + pub keys: Keymaps, +} + +#[test] +fn parsing_keymaps_config_file() { + use helix_core::hashmap; + use helix_view::document::Mode; + use helix_view::input::{KeyCode, KeyEvent, KeyModifiers}; + + let sample_keymaps = r#" + [keys.insert] + y = "move_line_down" + S-C-a = "delete_selection" + + [keys.normal] + A-F12 = "move_next_word_end" + "#; + + assert_eq!( + toml::from_str::<Config>(sample_keymaps).unwrap(), + Config { + global: Default::default(), + keys: Keymaps(hashmap! { + Mode::Insert => hashmap! { + KeyEvent { + code: KeyCode::Char('y'), + modifiers: KeyModifiers::NONE, + } => Command::move_line_down, + KeyEvent { + code: KeyCode::Char('a'), + modifiers: KeyModifiers::SHIFT | KeyModifiers::CONTROL, + } => Command::delete_selection, + }, + Mode::Normal => hashmap! { + KeyEvent { + code: KeyCode::F(12), + modifiers: KeyModifiers::ALT, + } => Command::move_next_word_end, + }, + }) + } + ); +} |