mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat(config): Add support for inverted token in style strings (#2589)
* Add support for `reverse` keyword in style strings * Duplicate test case and keep original * Rename keyword to `inverted` * Add explanatory sentence in readme
This commit is contained in:
+25
-2
@@ -359,7 +359,8 @@ impl StarshipConfig {
|
||||
- 'underline'
|
||||
- 'bold'
|
||||
- 'italic'
|
||||
- '<color>' (see the parse_color_string doc for valid color strings)
|
||||
- 'inverted'
|
||||
- '<color>' (see the parse_color_string doc for valid color strings)
|
||||
*/
|
||||
pub fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> {
|
||||
style_string
|
||||
@@ -383,6 +384,7 @@ pub fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> {
|
||||
"bold" => Some(style.bold()),
|
||||
"italic" => Some(style.italic()),
|
||||
"dimmed" => Some(style.dimmed()),
|
||||
"inverted" => Some(style.reverse()),
|
||||
// When the string is supposed to be a color:
|
||||
// Decide if we yield none, reset background or set color.
|
||||
color_string => {
|
||||
@@ -675,7 +677,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_get_styles_bold_italic_underline_green_dimmy_silly_caps() {
|
||||
fn table_get_styles_bold_italic_underline_green_dimmed_silly_caps() {
|
||||
let config = Value::from("bOlD ItAlIc uNdErLiNe GrEeN diMMeD");
|
||||
let mystyle = <Style>::from_config(&config).unwrap();
|
||||
assert!(mystyle.is_bold);
|
||||
@@ -693,6 +695,27 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_get_styles_bold_italic_underline_green_dimmed_inverted_silly_caps() {
|
||||
let config = Value::from("bOlD ItAlIc uNdErLiNe GrEeN diMMeD InVeRTed");
|
||||
let mystyle = <Style>::from_config(&config).unwrap();
|
||||
assert!(mystyle.is_bold);
|
||||
assert!(mystyle.is_italic);
|
||||
assert!(mystyle.is_underline);
|
||||
assert!(mystyle.is_dimmed);
|
||||
assert!(mystyle.is_reverse);
|
||||
assert_eq!(
|
||||
mystyle,
|
||||
ansi_term::Style::new()
|
||||
.bold()
|
||||
.italic()
|
||||
.underline()
|
||||
.dimmed()
|
||||
.reverse()
|
||||
.fg(Color::Green)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_get_styles_plain_and_broken_styles() {
|
||||
// Test a "plain" style with no formatting
|
||||
|
||||
Reference in New Issue
Block a user