Skip to content

Commit

Permalink
Use prefix ansi: for ansi 3-bit colours
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Toohey authored and sharkdp committed Jan 16, 2024
1 parent 798a661 commit d3e9c06
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ impl Color {

fn from_ansi_name(s: &str) -> Result<Color> {
match s {
"black" => Ok(Self::Ansi3Bit(Ansi3Bit::Black)),
"red" => Ok(Self::Ansi3Bit(Ansi3Bit::Red)),
"green" => Ok(Self::Ansi3Bit(Ansi3Bit::Green)),
"yellow" => Ok(Self::Ansi3Bit(Ansi3Bit::Yellow)),
"blue" => Ok(Self::Ansi3Bit(Ansi3Bit::Blue)),
"magenta" => Ok(Self::Ansi3Bit(Ansi3Bit::Magenta)),
"cyan" => Ok(Self::Ansi3Bit(Ansi3Bit::Cyan)),
"white" => Ok(Self::Ansi3Bit(Ansi3Bit::White)),
"bright_black" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightBlack)),
"bright_red" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightRed)),
"bright_green" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightGreen)),
"bright_yellow" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightYellow)),
"bright_blue" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightBlue)),
"bright_magenta" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightMagenta)),
"bright_cyan" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightCyan)),
"bright_white" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightWhite)),
"ansi:black" => Ok(Self::Ansi3Bit(Ansi3Bit::Black)),
"ansi:red" => Ok(Self::Ansi3Bit(Ansi3Bit::Red)),
"ansi:green" => Ok(Self::Ansi3Bit(Ansi3Bit::Green)),
"ansi:yellow" => Ok(Self::Ansi3Bit(Ansi3Bit::Yellow)),
"ansi:blue" => Ok(Self::Ansi3Bit(Ansi3Bit::Blue)),
"ansi:magenta" => Ok(Self::Ansi3Bit(Ansi3Bit::Magenta)),
"ansi:cyan" => Ok(Self::Ansi3Bit(Ansi3Bit::Cyan)),
"ansi:white" => Ok(Self::Ansi3Bit(Ansi3Bit::White)),
"ansi:bright_black" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightBlack)),
"ansi:bright_red" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightRed)),
"ansi:bright_green" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightGreen)),
"ansi:bright_yellow" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightYellow)),
"ansi:bright_blue" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightBlue)),
"ansi:bright_magenta" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightMagenta)),
"ansi:bright_cyan" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightCyan)),
"ansi:bright_white" => Ok(Self::Ansi3Bit(Ansi3Bit::BrightWhite)),
_ => Err(VividError::ColorParseError(s.to_string())),
}
}
Expand Down Expand Up @@ -192,15 +192,21 @@ mod tests {

#[test]
fn ansi_3bit() {
assert_eq!(Color::Ansi3Bit(Ansi3Bit::Black), "black".parse().unwrap());
assert_eq!(Color::Ansi3Bit(Ansi3Bit::Green), "green".parse().unwrap());
assert_eq!(
Color::Ansi3Bit(Ansi3Bit::Black),
"ansi:black".parse().unwrap()
);
assert_eq!(
Color::Ansi3Bit(Ansi3Bit::Green),
"ansi:green".parse().unwrap()
);
assert_eq!(
Color::Ansi3Bit(Ansi3Bit::BrightYellow),
"bright_yellow".parse().unwrap()
"ansi:bright_yellow".parse().unwrap()
);
assert_eq!(
Color::Ansi3Bit(Ansi3Bit::BrightCyan),
"bright_cyan".parse().unwrap()
"ansi:bright_cyan".parse().unwrap()
);
}
}

0 comments on commit d3e9c06

Please sign in to comment.