summaryrefslogtreecommitdiffstats
path: root/src/utils/syntect.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-11-21 22:09:51 -0500
committerGitHub <noreply@github.com>2021-11-21 22:09:51 -0500
commit48173248dac85d6d6871554030e4a07e06c9ecdd (patch)
treeee04a945624c64dacb518af91cee976e488c5a19 /src/utils/syntect.rs
parent0a0a3e02addfdb33adc4e72d361cef392f47f189 (diff)
Support named colors (#786)
https://docs.rs/palette/0.6.0/palette/named/index.html
Diffstat (limited to 'src/utils/syntect.rs')
-rw-r--r--src/utils/syntect.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/utils/syntect.rs b/src/utils/syntect.rs
index 6f7e4af5..99b358da 100644
--- a/src/utils/syntect.rs
+++ b/src/utils/syntect.rs
@@ -9,6 +9,15 @@ pub fn syntect_color_from_ansi_name(name: &str) -> Option<Color> {
color::ansi_16_color_name_to_number(name).and_then(syntect_color_from_ansi_number)
}
+pub fn syntect_color_from_name(name: &str) -> Option<Color> {
+ palette::named::from_str(name).map(|color| Color {
+ r: color.red,
+ g: color.green,
+ b: color.blue,
+ a: 0xFF,
+ })
+}
+
/// Convert 8-bit ANSI code to #RGBA string with ANSI code in red channel and 0 in alpha channel.
// See https://github.com/sharkdp/bat/pull/543
pub fn syntect_color_from_ansi_number(n: u8) -> Option<Color> {