mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
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:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user