Now reading aliases and hotkeys

This commit is contained in:
Justine Pelletreau
2023-02-17 18:12:39 +01:00
parent 344f14c86f
commit 6abe6d886d
2 changed files with 36 additions and 3 deletions

View File

@ -7,7 +7,7 @@ use regex::Regex;
extern crate dirs;
extern crate yaml_rust;
use yaml_rust::{YamlLoader};
use yaml_rust::{YamlLoader, Yaml};
#[derive(Debug)]
pub struct SqishConf {
@ -44,13 +44,23 @@ impl SqishConf {
let sqishrc = &sqishrc[0];
let out_str = String::from(sqishrc["prompt"].as_str().unwrap());
//Loading hotkeys and aliases from yaml
//They can be empty, be careful...
let aliases_yaml = &sqishrc["aliases"];
let aliases = Self::yaml_dict2hashmap(aliases_yaml);
let hotkeys_yaml = &sqishrc["hotkeys"];
let hotkeys = Self::yaml_dict2hashmap(hotkeys_yaml);
let mut out_conf = SqishConf {
promptline: out_str.clone(),
promptline_base: out_str,
aliases: HashMap::new(),
hotkeys: HashMap::new(),
aliases: aliases,
hotkeys: hotkeys,
};
println!("{:?}", out_conf);
out_conf.handle_rgb();
out_conf.handle_colors();
@ -164,5 +174,18 @@ impl SqishConf {
}
}
///Takes a YAML dict and converts it into an hashmap.
fn yaml_dict2hashmap(yaml_dict: &Yaml) -> HashMap<String, String> {
let mut my_hashmap = HashMap::new();
if let Yaml::Hash(h) = yaml_dict {
for (k, v) in h.iter() {
if let (Yaml::String(k), Yaml::String(v)) = (k, v) {
my_hashmap.insert(k.clone(), v.clone());
}
}
}
return my_hashmap;
}
}