allow fg, bg, attributes to be set for all colors in color_config (#489)

* allow fg, bg, attributes to be set for all colors in color_config

* no need for comma between each key value
This commit is contained in:
Darren Schroeder
2021-12-14 13:34:39 -06:00
committed by GitHub
parent 04a9c8f3fd
commit a5c1dd0da5
2 changed files with 136 additions and 18 deletions

View File

@ -65,10 +65,40 @@ impl Value {
config.use_ls_colors = value.as_bool()?;
}
"color_config" => {
let (cols, vals) = value.as_record()?;
let (cols, inner_vals) = value.as_record()?;
let mut hm = HashMap::new();
for (k, v) in cols.iter().zip(vals) {
hm.insert(k.to_string(), v.as_string()?);
for (k, v) in cols.iter().zip(inner_vals) {
match &v {
Value::Record {
cols: inner_cols,
vals: inner_vals,
span: _,
} => {
// make a string from our config.color_config section that
// looks like this: { fg: "#rrggbb" bg: "#rrggbb" attr: "abc", }
// the real key here was to have quotes around the values but not
// require them around the keys.
// maybe there's a better way to generate this but i'm not sure
// what it is.
let key = k.to_string();
let mut val: String = inner_cols
.iter()
.zip(inner_vals)
.map(|(x, y)| {
let clony = y.clone();
format!("{}: \"{}\" ", x, clony.into_string(", ", &config))
})
.collect();
// now insert the braces at the front and the back to fake the json string
val.insert(0, '{');
val.push('}');
hm.insert(key, val);
}
_ => {
hm.insert(k.to_string(), v.as_string()?);
}
}
}
config.color_config = hm;
}