mirror of
https://github.com/starship/starship.git
synced 2024-11-29 19:53:38 +01:00
feat: Add support for blink, hidden, and strikethrough styles. (#4138)
Add support for blink, hidden, and strikethrough styles.
This commit is contained in:
parent
dd73447329
commit
aaab920f88
@ -278,6 +278,9 @@ Style strings are a list of words, separated by whitespace. The words are not ca
|
|||||||
- `underline`
|
- `underline`
|
||||||
- `dimmed`
|
- `dimmed`
|
||||||
- `inverted`
|
- `inverted`
|
||||||
|
- `blink`
|
||||||
|
- `hidden`
|
||||||
|
- `strikethrough`
|
||||||
- `bg:<color>`
|
- `bg:<color>`
|
||||||
- `fg:<color>`
|
- `fg:<color>`
|
||||||
- `<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).
|
- 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.
|
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
|
||||||
|
@ -268,6 +268,7 @@ where
|
|||||||
- 'bold'
|
- 'bold'
|
||||||
- 'italic'
|
- 'italic'
|
||||||
- 'inverted'
|
- 'inverted'
|
||||||
|
- 'blink'
|
||||||
- '<color>' (see the `parse_color_string` doc for valid color strings)
|
- '<color>' (see the `parse_color_string` doc for valid color strings)
|
||||||
*/
|
*/
|
||||||
pub fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> {
|
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()),
|
"italic" => Some(style.italic()),
|
||||||
"dimmed" => Some(style.dimmed()),
|
"dimmed" => Some(style.dimmed()),
|
||||||
"inverted" => Some(style.reverse()),
|
"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:
|
// When the string is supposed to be a color:
|
||||||
// Decide if we yield none, reset background or set color.
|
// Decide if we yield none, reset background or set color.
|
||||||
color_string => {
|
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]
|
#[test]
|
||||||
fn table_get_styles_plain_and_broken_styles() {
|
fn table_get_styles_plain_and_broken_styles() {
|
||||||
// Test a "plain" style with no formatting
|
// Test a "plain" style with no formatting
|
||||||
|
Loading…
Reference in New Issue
Block a user