fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> {
    let tokens = style_string.split_whitespace();
    let mut style = ansi_term::Style::new();

    // If col_fg is true, color the foreground. If it's false, color the background.
    let mut col_fg: bool;

    for token in tokens {
        let token = token.to_lowercase();

        // Check for FG/BG identifiers and strip them off if appropriate
        let token = if token.as_str().starts_with("fg:") {
            col_fg = true;
            token.trim_start_matches("fg:").to_owned()
        } else if token.as_str().starts_with("bg:") {
            col_fg = false;
            token.trim_start_matches("bg:").to_owned()
        } else {
            col_fg = true; // Bare colors are assumed to color the foreground
            token
        };

        match token.as_str() {
            "underline" => style = style.underline(),
            "bold" => style = style.bold(),
            "dimmed" => style = style.dimmed(),
            "none" => return Some(ansi_term::Style::new()), // Overrides other toks

            // Try to see if this token parses as a valid color string
            color_string => {
                // Match found: set either fg or bg color
                if let Some(ansi_color) = parse_color_string(color_string) {
                    if col_fg {
                        style = style.fg(ansi_color);
                    } else {
                        style = style.on(ansi_color);
                    }
                } else {
                    // Match failed: skip this token and log it
                    log::debug!("Could not parse token in color string: {}", token)
                }
            }
        }
    }

    Some(style)
}
/** Parse a style string which represents an ansi style. Valid tokens in the style
 string include the following:
 - 'fg:<color>'    (specifies that the color read should be a foreground color)
 - 'bg:<color>'    (specifies that the color read should be a background color)
 - 'underline'
 - 'bold'
 - '<color>'        (see the parse_color_string doc for valid color strings)
*/
Parse a style string which represents an ansi style.
Parse a style string which represents an ansi style .
fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> {
    let tokens = style_string.split_whitespace();
    let mut style = ansi_term::Style::new();
    // If col_fg is true, color the foreground. If it's false, color the background.
    let mut col_fg: bool;
    for token in tokens {
        let token = token.to_lowercase();
        // Check for FG/BG identifiers and strip them off if appropriate
        let token = if token.as_str().starts_with("fg:") {
            col_fg = true;
            token.trim_start_matches("fg:").to_owned()
        } else if token.as_str().starts_with("bg:") {
            col_fg = false;
            token.trim_start_matches("bg:").to_owned()
        } else {
            col_fg = true; // Bare colors are assumed to color the foreground
            token
        };
        match token.as_str() {
            "underline" => style = style.underline(),
            "bold" => style = style.bold(),
            "dimmed" => style = style.dimmed(),
            "none" => return Some(ansi_term::Style::new()), // Overrides other toks
            // Try to see if this token parses as a valid color string
            color_string => {
                // Match found: set either fg or bg color
                if let Some(ansi_color) = parse_color_string(color_string) {
                    if col_fg {
                        style = style.fg(ansi_color);
                    } else {
                        style = style.on(ansi_color);
                    }
                } else {
                    // Match failed: skip this token and log it
                    log::debug!("Could not parse token in color string: {}", token)
                }
            }
        }
    }
    Some(style)
}
fn parse_style_string ( style_string : & str ) -> Option < ansi_term :: Style > { let tokens = style_string . split_whitespace ( ) ; let mut style = ansi_term :: Style :: new ( ) ; // If col_fg is true, color the foreground. If it's false, color the background. let mut col_fg : bool ; for token in tokens { let token = token . to_lowercase ( ) ; // Check for FG/BG identifiers and strip them off if appropriate let token = if token . as_str ( ) . starts_with ( " " ) { col_fg = true ; token . trim_start_matches ( " " ) . to_owned ( ) } else if token . as_str ( ) . starts_with ( " " ) { col_fg = false ; token . trim_start_matches ( " " ) . to_owned ( ) } else { col_fg = true ; // Bare colors are assumed to color the foreground token } ; match token . as_str ( ) { " " => style = style . underline ( ) , " " => style = style . bold ( ) , " " => style = style . dimmed ( ) , " " => return Some ( ansi_term :: Style :: new ( ) ) , // Overrides other toks // Try to see if this token parses as a valid color string color_string => { // Match found: set either fg or bg color if let Some ( ansi_color ) = parse_color_string ( color_string ) { if col_fg { style = style . fg ( ansi_color ) ; } else { style = style . on ( ansi_color ) ; } } else { // Match failed: skip this token and log it log :: debug ! ( " " token ) } } } } Some ( style ) }
Parse a style string which represents an ansi style.
Parse a style string which represents an ansi style .
style_string
&str