diff options
author | PabloMansanet | 2021-06-17 11:08:05 +0000 |
---|---|---|
committer | GitHub | 2021-06-17 11:08:05 +0000 |
commit | f7e00cf720f55ea82933ac6625b7511e9d38139e (patch) | |
tree | dc8278b34332eebea8b137d15cca9e5fb08b2b06 /helix-term/src/config.rs | |
parent | 47d2e3aefa5d31c19e7def624057a29c4bc7bc41 (diff) |
Configurable keys 2 (Mapping keys to commands) (#268)
* Add convenience/clarity wrapper for Range initialization
* Add keycode parse and display methods
* Add remapping functions and tests
* Implement key remapping
* Add remapping book entry
* Use raw string literal for toml
* Add command constants
* Make command functions private
* Map directly to commands
* Match key parsing/displaying to Kakoune
* Formatting pass
* Update documentation
* Formatting
* Fix example in the book
* Refactor into single config file
* Formatting
* Refactor configuration and add keymap newtype wrappers
* Address first batch of PR comments
* Replace FromStr with custom deserialize
Diffstat (limited to 'helix-term/src/config.rs')
-rw-r--r-- | helix-term/src/config.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs new file mode 100644 index 00000000..bd84e0b1 --- /dev/null +++ b/helix-term/src/config.rs @@ -0,0 +1,33 @@ +use anyhow::{Error, Result}; +use std::{collections::HashMap, str::FromStr}; + +use serde::{de::Error as SerdeError, Deserialize, Serialize}; + +use crate::keymap::{parse_keymaps, Keymaps}; + +#[derive(Default)] +pub struct Config { + pub keymaps: Keymaps, +} + +#[derive(Serialize, Deserialize)] +struct TomlConfig { + keys: Option<HashMap<String, HashMap<String, String>>>, +} + +impl<'de> Deserialize<'de> for Config { + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> + where + D: serde::Deserializer<'de>, + { + let config = TomlConfig::deserialize(deserializer)?; + Ok(Self { + keymaps: config + .keys + .map(|r| parse_keymaps(&r)) + .transpose() + .map_err(|e| D::Error::custom(format!("Error deserializing keymap: {}", e)))? + .unwrap_or_else(Keymaps::default), + }) + } +} |