mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01:00
add hex color parsing to ansi (#5209)
This commit is contained in:
parent
1bad40726d
commit
4d31139a44
@ -375,15 +375,32 @@ Format: #
|
|||||||
// OCS's need to end with a bell '\x07' char
|
// OCS's need to end with a bell '\x07' char
|
||||||
format!("\x1b]{};", code_string)
|
format!("\x1b]{};", code_string)
|
||||||
} else if param_is_valid_string {
|
} else if param_is_valid_string {
|
||||||
match str_to_ansi(&code_string) {
|
// parse hex colors like #00FF00
|
||||||
Some(c) => c,
|
if code_string.starts_with('#') {
|
||||||
None => {
|
match nu_color_config::color_from_hex(&code_string) {
|
||||||
return Err(ShellError::UnsupportedInput(
|
Ok(color) => match color {
|
||||||
String::from("Unknown ansi code"),
|
Some(c) => c.prefix().to_string(),
|
||||||
call.positional_nth(0)
|
None => Color::White.prefix().to_string(),
|
||||||
.expect("Unexpected missing argument")
|
},
|
||||||
.span,
|
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 => {
|
||||||
|
return Err(ShellError::UnsupportedInput(
|
||||||
|
String::from("Unknown ansi code"),
|
||||||
|
call.positional_nth(0)
|
||||||
|
.expect("Unexpected missing argument")
|
||||||
|
.span,
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user