summaryrefslogtreecommitdiffstats
path: root/src
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
parent0a0a3e02addfdb33adc4e72d361cef392f47f189 (diff)
Support named colors (#786)
https://docs.rs/palette/0.6.0/palette/named/index.html
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs12
-rw-r--r--src/color.rs1
-rw-r--r--src/utils/syntect.rs9
3 files changed, 18 insertions, 4 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 5b0fd6a6..558d2141 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -114,15 +114,19 @@ A complete description of the style string syntax follows:
COLORS
------
-There are three ways to specify a color (this section applies to foreground and background colors
+There are four ways to specify a color (this section applies to foreground and background colors
within a style string):
-1. RGB hex code
+1. CSS color name
+
+ Any of the 140 color names used in CSS: https://www.w3schools.com/colors/colors_groups.asp
+
+2. RGB hex code
An example of using an RGB hex code is:
--file-style=\"#0e7c0e\"
-2. ANSI color name
+3. ANSI color name
There are 8 ANSI color names:
black, red, green, yellow, blue, magenta, cyan, white.
@@ -141,7 +145,7 @@ within a style string):
\"purple\" is accepted as a synonym for \"magenta\". Color names and codes are case-insensitive.
-3. ANSI color number
+4. ANSI color number
An example of using an ANSI color number is:
--file-style=28
diff --git a/src/color.rs b/src/color.rs
index c816e158..6f617baf 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -22,6 +22,7 @@ pub fn parse_color(s: &str, true_color: bool) -> Option<Color> {
.ok()
.and_then(utils::syntect::syntect_color_from_ansi_number)
.or_else(|| utils::syntect::syntect_color_from_ansi_name(s))
+ .or_else(|| utils::syntect::syntect_color_from_name(s))
.unwrap_or_else(die)
};
utils::bat::terminal::to_ansi_color(syntect_color, true_color)
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> {