Function syntect_tui::translate_colour
source · pub fn translate_colour(syntect_color: Color) -> Option<Color>
Expand description
Converts a syntect::highlighting::Color into a ratatui::style::Color.
§Examples
Basic usage:
let input = syntect::highlighting::Color { r: 255, g: 0, b: 0, a: 255 };
let expected = Some(ratatui::style::Color::Rgb(255, 0, 0));
let actual = syntect_tui::translate_colour(input);
assert_eq!(expected, actual);
Syntect colours are RGBA while Ratatui colours are RGB, so colour conversion is lossy. However, if a Syntect colour’s alpha value is 0
, then we preserve this to some degree by returning a value of None
for that colour (i.e. colourless):
assert_eq!(
None,
syntect_tui::translate_colour(syntect::highlighting::Color { r: 255, g: 0, b: 0, a: 0 })
);