|
|
|
@ -53,25 +53,38 @@ pub struct Config {
|
|
|
|
|
pub keymap_table: HashMap<Key, Vec<KeymapEntry>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ConfigFiletype {
|
|
|
|
|
Yaml,
|
|
|
|
|
Toml,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_file_ext(filename: &PathBuf) -> ConfigFiletype {
|
|
|
|
|
match filename.extension() {
|
|
|
|
|
Some(f) => {
|
|
|
|
|
if f.to_str().unwrap_or("").to_lowercase() == "toml" {
|
|
|
|
|
ConfigFiletype::Toml
|
|
|
|
|
} else {
|
|
|
|
|
ConfigFiletype::Yaml
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
_ => ConfigFiletype::Yaml,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn load_configs(filenames: &Vec<PathBuf>) -> Result<Config, Box<dyn error::Error>> {
|
|
|
|
|
// Assumes filenames is non-empty
|
|
|
|
|
let config_contents = fs::read_to_string(&filenames[0])?;
|
|
|
|
|
let mut is_yaml = true;
|
|
|
|
|
|
|
|
|
|
let mut config: Config = {
|
|
|
|
|
match serde_yaml::from_str(&config_contents) {
|
|
|
|
|
Ok(c) => c,
|
|
|
|
|
Err(_) => { is_yaml = false; toml::from_str(&config_contents)? }
|
|
|
|
|
}
|
|
|
|
|
let mut config: Config = match get_file_ext(&filenames[0]) {
|
|
|
|
|
ConfigFiletype::Yaml => serde_yaml::from_str(&config_contents)?,
|
|
|
|
|
ConfigFiletype::Toml => toml::from_str(&config_contents)?,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for filename in &filenames[1..] {
|
|
|
|
|
let config_contents = fs::read_to_string(&filename)?;
|
|
|
|
|
let c: Config = {
|
|
|
|
|
match is_yaml {
|
|
|
|
|
true => serde_yaml::from_str(&config_contents)?,
|
|
|
|
|
false => toml::from_str(&config_contents)?
|
|
|
|
|
}
|
|
|
|
|
let c: Config = match get_file_ext(&filename) {
|
|
|
|
|
ConfigFiletype::Yaml => serde_yaml::from_str(&config_contents)?,
|
|
|
|
|
ConfigFiletype::Toml => serde_yaml::from_str(&config_contents)?,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config.modmap.extend(c.modmap);
|
|
|
|
|