From fd63c6bd5758e8df38163a6f8131407a36745249 Mon Sep 17 00:00:00 2001 From: alice pellerin Date: Sun, 26 Apr 2026 00:25:00 -0500 Subject: [PATCH] merge custom config with default instead of replacing --- src/config.rs | 39 +++++++++++++++++++++++++++++++++++++-- src/main.rs | 4 ---- 2 files changed, 37 insertions(+), 6 deletions(-) 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();