Fix #7551 record support in color_config (#7567)

Closes https://github.com/nushell/nushell/issues/7551
This commit is contained in:
Leon 2022-12-22 21:55:50 +10:00 committed by GitHub
parent d8a2e0e9a3
commit 74656bf976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,14 +1,10 @@
use crate::color_config::lookup_ansi_color_style; use crate::{color_config::lookup_ansi_color_style, color_record_to_nustyle};
use nu_ansi_term::{Color, Style}; use nu_ansi_term::{Color, Style};
use nu_protocol::Config; use nu_protocol::{Config, Value};
pub fn get_shape_color(shape: String, conf: &Config) -> Style { // The default colors for shapes, used when there is no config for them.
match conf.color_config.get(shape.as_str()) { pub fn default_shape_color(shape: String) -> Style {
Some(int_color) => match int_color.as_string() { match shape.as_ref() {
Ok(int_color) => lookup_ansi_color_style(&int_color),
Err(_) => Style::default(),
},
None => match shape.as_ref() {
"shape_and" => Style::new().fg(Color::Purple).bold(), "shape_and" => Style::new().fg(Color::Purple).bold(),
"shape_binary" => Style::new().fg(Color::Purple).bold(), "shape_binary" => Style::new().fg(Color::Purple).bold(),
"shape_block" => Style::new().fg(Color::Blue).bold(), "shape_block" => Style::new().fg(Color::Blue).bold(),
@ -40,6 +36,21 @@ pub fn get_shape_color(shape: String, conf: &Config) -> Style {
"shape_table" => Style::new().fg(Color::Blue).bold(), "shape_table" => Style::new().fg(Color::Blue).bold(),
"shape_variable" => Style::new().fg(Color::Purple), "shape_variable" => Style::new().fg(Color::Purple),
_ => Style::default(), _ => Style::default(),
}, }
}
pub fn get_shape_color(shape: String, conf: &Config) -> Style {
match conf.color_config.get(shape.as_str()) {
Some(int_color) => {
// Shapes do not use color_config closures, currently.
match int_color {
Value::Record { .. } => color_record_to_nustyle(int_color),
Value::String { val, .. } => lookup_ansi_color_style(val),
// Defer to the default in the event of incorrect types being given
// (i.e. treat null, etc. as the value being unset)
_ => default_shape_color(shape),
}
}
None => default_shape_color(shape),
} }
} }