1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-28 20:12:42 +00:00

feat: Add support for blink, hidden, and strikethrough styles. (#4138)

Add support for blink, hidden, and strikethrough styles.
This commit is contained in:
Davin K. Tanabe 2022-07-31 10:30:34 -04:00 committed by GitHub
parent dd73447329
commit aaab920f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 0 deletions

View File

@ -278,6 +278,9 @@ Style strings are a list of words, separated by whitespace. The words are not ca
- `underline`
- `dimmed`
- `inverted`
- `blink`
- `hidden`
- `strikethrough`
- `bg:<color>`
- `fg:<color>`
- `<color>`
@ -297,3 +300,9 @@ A color specifier can be one of the following:
- A number between 0-255. This specifies an [8-bit ANSI Color Code](https://i.stack.imgur.com/KTSQa.png).
If multiple colors are specified for foreground/background, the last one in the string will take priority.
Not every style string will be displayed correctly by every terminal. In particular, the following known quirks exist:
- Many terminals disable support for `blink` by default
- `hidden` is not supported on iTerm (https://gitlab.com/gnachman/iterm2/-/issues/4564).
- `strikethrough` is not supported by the default macOS Terminal.app

View File

@ -268,6 +268,7 @@ where
- 'bold'
- 'italic'
- 'inverted'
- 'blink'
- '<color>' (see the `parse_color_string` doc for valid color strings)
*/
pub fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> {
@ -293,6 +294,9 @@ pub fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> {
"italic" => Some(style.italic()),
"dimmed" => Some(style.dimmed()),
"inverted" => Some(style.reverse()),
"blink" => Some(style.blink()),
"hidden" => Some(style.hidden()),
"strikethrough" => Some(style.strikethrough()),
// When the string is supposed to be a color:
// Decide if we yield none, reset background or set color.
color_string => {
@ -626,6 +630,69 @@ mod tests {
);
}
#[test]
fn table_get_styles_bold_italic_underline_green_dimmed_blink_silly_caps() {
let config = Value::from("bOlD ItAlIc uNdErLiNe GrEeN diMMeD bLiNk");
let mystyle = <StyleWrapper>::from_config(&config).unwrap().0;
assert!(mystyle.is_bold);
assert!(mystyle.is_italic);
assert!(mystyle.is_underline);
assert!(mystyle.is_dimmed);
assert!(mystyle.is_blink);
assert_eq!(
mystyle,
ansi_term::Style::new()
.bold()
.italic()
.underline()
.dimmed()
.blink()
.fg(Color::Green)
);
}
#[test]
fn table_get_styles_bold_italic_underline_green_dimmed_hidden_silly_caps() {
let config = Value::from("bOlD ItAlIc uNdErLiNe GrEeN diMMeD hIDDen");
let mystyle = <StyleWrapper>::from_config(&config).unwrap().0;
assert!(mystyle.is_bold);
assert!(mystyle.is_italic);
assert!(mystyle.is_underline);
assert!(mystyle.is_dimmed);
assert!(mystyle.is_hidden);
assert_eq!(
mystyle,
ansi_term::Style::new()
.bold()
.italic()
.underline()
.dimmed()
.hidden()
.fg(Color::Green)
);
}
#[test]
fn table_get_styles_bold_italic_underline_green_dimmed_strikethrough_silly_caps() {
let config = Value::from("bOlD ItAlIc uNdErLiNe GrEeN diMMeD StRiKEthROUgh");
let mystyle = <StyleWrapper>::from_config(&config).unwrap().0;
assert!(mystyle.is_bold);
assert!(mystyle.is_italic);
assert!(mystyle.is_underline);
assert!(mystyle.is_dimmed);
assert!(mystyle.is_strikethrough);
assert_eq!(
mystyle,
ansi_term::Style::new()
.bold()
.italic()
.underline()
.dimmed()
.strikethrough()
.fg(Color::Green)
);
}
#[test]
fn table_get_styles_plain_and_broken_styles() {
// Test a "plain" style with no formatting