diff --git a/src/config.rs b/src/config.rs index b62f7e2..00f1d46 100644 --- a/src/config.rs +++ b/src/config.rs @@ -45,7 +45,7 @@ impl Config { #[cfg(windows)] fn default_path() -> Option { // this isn't technically the right way but it should be good enough - home_dir().map(|home| home.join("AppData").join("Roaming")) + home_dir().map(|home| home.join("AppData").join("Roaming").join("hexapoda.toml")) } pub fn path(override_path: Option) -> Option { @@ -58,7 +58,21 @@ impl Config { let raw_config = read_to_string(path)?; - Ok(toml::from_str(&raw_config)?) + Ok(Self::default().combined_with(toml::from_str(&raw_config)?)) + } + + fn combined_with(mut self, other: Self) -> Self { + for (mode, mode_config) in other.0 { + match self.0.entry(mode) { + Entry::Occupied(mut occupied_entry) => { + occupied_entry.get_mut().combine_with(mode_config); + } + Entry::Vacant(vacant_entry) => { + vacant_entry.insert(mode_config); + } + } + } + self } } @@ -78,6 +92,27 @@ impl From for ConfigInitError { } } +impl ModeConfig { + fn combine_with(&mut self, other: Self) { + for (partial_action, keybinds) in other.0 { + match self.0.entry(partial_action) { + Entry::Occupied(mut occupied_entry) => { + occupied_entry.get_mut().combine_with(keybinds); + } + Entry::Vacant(vacant_entry) => { + vacant_entry.insert(keybinds); + } + } + } + } +} + +impl Keybinds { + fn combine_with(&mut self, other: Self) { + self.0.extend(other.0); + } +} + impl Serialize for ModeConfig { fn serialize(&self, serializer: S) -> Result { let mut map = serializer.serialize_map(None)?; diff --git a/src/main.rs b/src/main.rs index f5b655e..940b9f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,10 +73,6 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // - [/] to cycle view offset? // - gj jump to entered offset -// future directions -// - 'views' for bytes (i8/16/etc u8/16/etc 20.12/8.4/etc) -// - how to fit??! `-128` longer than `80` - fn main() { let arguments = Arguments::parse();