diff --git a/docs/advanced-config/README.md b/docs/advanced-config/README.md index ea71bc1b..e030cadf 100644 --- a/docs/advanced-config/README.md +++ b/docs/advanced-config/README.md @@ -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:` - `fg:` - `` @@ -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 diff --git a/src/config.rs b/src/config.rs index b4a93d40..faeba829 100644 --- a/src/config.rs +++ b/src/config.rs @@ -268,6 +268,7 @@ where - 'bold' - 'italic' - 'inverted' + - 'blink' - '' (see the `parse_color_string` doc for valid color strings) */ pub fn parse_style_string(style_string: &str) -> Option { @@ -293,6 +294,9 @@ pub fn parse_style_string(style_string: &str) -> Option { "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 = ::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 = ::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 = ::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