fn parse_color_string(color_string: &str) -> Option<ansi_term::Color> {
    // Parse RGB hex values
    log::trace!("Parsing color_string: {}", color_string);
    if color_string.starts_with('#') {
        log::trace!(
            "Attempting to read hexadecimal color string: {}",
            color_string
        );
        let r: u8 = u8::from_str_radix(&color_string[1..3], 16).ok()?;
        let g: u8 = u8::from_str_radix(&color_string[3..5], 16).ok()?;
        let b: u8 = u8::from_str_radix(&color_string[5..7], 16).ok()?;
        log::trace!("Read RGB color string: {},{},{}", r, g, b);
        return Some(Color::RGB(r, g, b));
    }

    // Parse a u8 (ansi color)
    if let Result::Ok(ansi_color_num) = color_string.parse::<u8>() {
        log::trace!("Read ANSI color string: {}", ansi_color_num);
        return Some(Color::Fixed(ansi_color_num));
    }

    // Check for any predefined color strings
    // There are no predefined enums for bright colors, so we use Color::Fixed
    let predefined_color = match color_string.to_lowercase().as_str() {
        "black" => Some(Color::Black),
        "red" => Some(Color::Red),
        "green" => Some(Color::Green),
        "yellow" => Some(Color::Yellow),
        "blue" => Some(Color::Blue),
        "purple" => Some(Color::Purple),
        "cyan" => Some(Color::Cyan),
        "white" => Some(Color::White),
        "bright-black" => Some(Color::Fixed(8)), // "bright-black" is dark grey
        "bright-red" => Some(Color::Fixed(9)),
        "bright-green" => Some(Color::Fixed(10)),
        "bright-yellow" => Some(Color::Fixed(11)),
        "bright-blue" => Some(Color::Fixed(12)),
        "bright-purple" => Some(Color::Fixed(13)),
        "bright-cyan" => Some(Color::Fixed(14)),
        "bright-white" => Some(Color::Fixed(15)),
        _ => None,
    };

    if predefined_color.is_some() {
        log::trace!("Read predefined color: {}", color_string);
        return predefined_color;
    }

    // All attempts to parse have failed
    None
}
/** Parse a string that represents a color setting, returning None if this fails
 There are three valid color formats:
  - #RRGGBB      (a hash followed by an RGB hex)
  - u8           (a number from 0-255, representing an ANSI color)
  - colstring    (one of the 16 predefined color strings)
*/
Parse a string that represents a color setting, returning None if this fails
There are three valid color formats:
#RRGGBB      (a hash followed by an RGB hex)
u8           (a number from 0-255, representing an ANSI color)
colstring    (one of the 16 predefined color strings)
Parse a string that represents a color setting returning None if this fails There are three valid color formats : #RRGGBB ( a hash followed by an RGB hex ) u8 ( a number from 0 - 255 representing an ANSI color ) colstring ( one of the 16 predefined color strings )
fn parse_color_string(color_string: &str) -> Option<ansi_term::Color> {
    // Parse RGB hex values
    log::trace!("Parsing color_string: {}", color_string);
    if color_string.starts_with('#') {
        log::trace!(
            "Attempting to read hexadecimal color string: {}",
            color_string
        );
        let r: u8 = u8::from_str_radix(&color_string[1..3], 16).ok()?;
        let g: u8 = u8::from_str_radix(&color_string[3..5], 16).ok()?;
        let b: u8 = u8::from_str_radix(&color_string[5..7], 16).ok()?;
        log::trace!("Read RGB color string: {},{},{}", r, g, b);
        return Some(Color::RGB(r, g, b));
    }
    // Parse a u8 (ansi color)
    if let Result::Ok(ansi_color_num) = color_string.parse::<u8>() {
        log::trace!("Read ANSI color string: {}", ansi_color_num);
        return Some(Color::Fixed(ansi_color_num));
    }
    // Check for any predefined color strings
    // There are no predefined enums for bright colors, so we use Color::Fixed
    let predefined_color = match color_string.to_lowercase().as_str() {
        "black" => Some(Color::Black),
        "red" => Some(Color::Red),
        "green" => Some(Color::Green),
        "yellow" => Some(Color::Yellow),
        "blue" => Some(Color::Blue),
        "purple" => Some(Color::Purple),
        "cyan" => Some(Color::Cyan),
        "white" => Some(Color::White),
        "bright-black" => Some(Color::Fixed(8)), // "bright-black" is dark grey
        "bright-red" => Some(Color::Fixed(9)),
        "bright-green" => Some(Color::Fixed(10)),
        "bright-yellow" => Some(Color::Fixed(11)),
        "bright-blue" => Some(Color::Fixed(12)),
        "bright-purple" => Some(Color::Fixed(13)),
        "bright-cyan" => Some(Color::Fixed(14)),
        "bright-white" => Some(Color::Fixed(15)),
        _ => None,
    };
    if predefined_color.is_some() {
        log::trace!("Read predefined color: {}", color_string);
        return predefined_color;
    }
    // All attempts to parse have failed
    None
}
fn parse_color_string ( color_string : & str ) -> Option < ansi_term :: Color > { // Parse RGB hex values log :: trace ! ( " " color_string ) ; if color_string . starts_with ( '#' ) { log :: trace ! ( " " color_string ) ; let r : u8 = u8 :: from_str_radix ( & color_string [ 1 .. 3 ] , 16 ) . ok ( ) ? ; let g : u8 = u8 :: from_str_radix ( & color_string [ 3 .. 5 ] , 16 ) . ok ( ) ? ; let b : u8 = u8 :: from_str_radix ( & color_string [ 5 .. 7 ] , 16 ) . ok ( ) ? ; log :: trace ! ( " " r g b ) ; return Some ( Color :: RGB ( r , g , b ) ) ; } // Parse a u8 (ansi color) if let Result :: Ok ( ansi_color_num ) = color_string . parse :: < u8 > ( ) { log :: trace ! ( " " ansi_color_num ) ; return Some ( Color :: Fixed ( ansi_color_num ) ) ; } // Check for any predefined color strings // There are no predefined enums for bright colors, so we use Color::Fixed let predefined_color = match color_string . to_lowercase ( ) . as_str ( ) { " " => Some ( Color :: Black ) , " " => Some ( Color :: Red ) , " " => Some ( Color :: Green ) , " " => Some ( Color :: Yellow ) , " " => Some ( Color :: Blue ) , " " => Some ( Color :: Purple ) , " " => Some ( Color :: Cyan ) , " " => Some ( Color :: White ) , " " => Some ( Color :: Fixed ( 8 ) ) , // "bright-black" is dark grey " " => Some ( Color :: Fixed ( 9 ) ) , " " => Some ( Color :: Fixed ( 10 ) ) , " " => Some ( Color :: Fixed ( 11 ) ) , " " => Some ( Color :: Fixed ( 12 ) ) , " " => Some ( Color :: Fixed ( 13 ) ) , " " => Some ( Color :: Fixed ( 14 ) ) , " " => Some ( Color :: Fixed ( 15 ) ) , _ => None , } ; if predefined_color . is_some ( ) { log :: trace ! ( " " color_string ) ; return predefined_color ; } // All attempts to parse have failed None }
Parse a string that represents a color setting, returning None if this fails
There are three valid color formats:
 #RRGGBB      (a hash followed by an RGB hex)
 u8           (a number from 0-255, representing an ANSI color)
 colstring    (one of the 16 predefined color strings)
Parse a string that represents a color setting returning None if this fails There are three valid color formats : #RRGGBB ( a hash followed by an RGB hex ) u8 ( a number from 0 - 255 representing an ANSI color ) colstring ( one of the 16 predefined color strings )
color_string
&str