add hex color parsing to ansi (#5209)

This commit is contained in:
Darren Schroeder 2022-04-16 10:44:04 -05:00 committed by GitHub
parent 1bad40726d
commit 4d31139a44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -375,6 +375,22 @@ Format: #
// OCS's need to end with a bell '\x07' char
format!("\x1b]{};", code_string)
} else if param_is_valid_string {
// parse hex colors like #00FF00
if code_string.starts_with('#') {
match nu_color_config::color_from_hex(&code_string) {
Ok(color) => match color {
Some(c) => c.prefix().to_string(),
None => Color::White.prefix().to_string(),
},
Err(err) => {
return Err(ShellError::SpannedLabeledError(
"error parsing hex color".to_string(),
format!("{}", err),
code.span()?,
));
}
}
} else {
match str_to_ansi(&code_string) {
Some(c) => c,
None => {
@ -386,6 +402,7 @@ Format: #
))
}
}
}
} else {
// This is a record that should look like
// { fg: "#ff0000" bg: "#00ff00" attr: bli }