2021-06-22 19:04:04 +02:00
|
|
|
use serde::Deserialize;
|
2021-06-17 13:08:05 +02:00
|
|
|
|
2021-06-22 19:04:04 +02:00
|
|
|
use crate::keymap::Keymaps;
|
2021-06-19 16:59:19 +02:00
|
|
|
|
2021-06-22 19:04:04 +02:00
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
|
2021-06-17 13:08:05 +02:00
|
|
|
pub struct Config {
|
2021-06-20 21:31:45 +02:00
|
|
|
pub theme: Option<String>,
|
2021-06-22 19:04:04 +02:00
|
|
|
#[serde(default)]
|
2021-06-20 21:31:45 +02:00
|
|
|
pub lsp: LspConfig,
|
2021-06-22 19:04:04 +02:00
|
|
|
#[serde(default)]
|
|
|
|
pub keys: Keymaps,
|
2021-07-30 09:52:00 +02:00
|
|
|
#[serde(default)]
|
|
|
|
pub terminal: TerminalConfig,
|
2021-06-17 13:08:05 +02:00
|
|
|
}
|
|
|
|
|
2021-06-22 19:04:04 +02:00
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
|
2021-06-23 22:33:28 +02:00
|
|
|
#[serde(rename_all = "kebab-case")]
|
2021-06-20 21:31:45 +02:00
|
|
|
pub struct LspConfig {
|
|
|
|
pub display_messages: bool,
|
|
|
|
}
|
|
|
|
|
2021-07-30 09:52:00 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
pub struct TerminalConfig {
|
|
|
|
pub mouse: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TerminalConfig {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self { mouse: true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 19:04:04 +02:00
|
|
|
#[test]
|
|
|
|
fn parsing_keymaps_config_file() {
|
2021-07-26 18:07:13 +02:00
|
|
|
use crate::keymap;
|
|
|
|
use crate::keymap::Keymap;
|
2021-06-22 19:04:04 +02:00
|
|
|
use helix_core::hashmap;
|
2021-07-26 18:07:13 +02:00
|
|
|
use helix_view::document::Mode;
|
2021-06-22 19:04:04 +02:00
|
|
|
|
|
|
|
let sample_keymaps = r#"
|
|
|
|
[keys.insert]
|
|
|
|
y = "move_line_down"
|
|
|
|
S-C-a = "delete_selection"
|
|
|
|
|
|
|
|
[keys.normal]
|
|
|
|
A-F12 = "move_next_word_end"
|
|
|
|
"#;
|
2021-06-17 18:52:41 +02:00
|
|
|
|
2021-06-22 19:04:04 +02:00
|
|
|
assert_eq!(
|
|
|
|
toml::from_str::<Config>(sample_keymaps).unwrap(),
|
|
|
|
Config {
|
|
|
|
keys: Keymaps(hashmap! {
|
2021-07-26 18:07:13 +02:00
|
|
|
Mode::Insert => Keymap::new(keymap!({ "Insert mode"
|
|
|
|
"y" => move_line_down,
|
|
|
|
"S-C-a" => delete_selection,
|
|
|
|
})),
|
|
|
|
Mode::Normal => Keymap::new(keymap!({ "Normal mode"
|
|
|
|
"A-F12" => move_next_word_end,
|
|
|
|
})),
|
2021-06-22 19:04:04 +02:00
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
);
|
2021-06-17 13:08:05 +02:00
|
|
|
}
|