summaryrefslogtreecommitdiffstats
path: root/src/color.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-07-12 16:37:59 -0400
committerDan Davison <dandavison7@gmail.com>2020-07-13 10:43:41 -0400
commit3c1610ffd605bc775f160840ecb195449128e736 (patch)
tree06f670ac299a92330053f2ffac8af811baa1d5db /src/color.rs
parentd99a64c8c383e196693e438652eb2ad5006e48bc (diff)
Refactor: simplify color parsing
Diffstat (limited to 'src/color.rs')
-rw-r--r--src/color.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/color.rs b/src/color.rs
index 53d6a929..ed0f4f75 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -9,7 +9,10 @@ use syntect::highlighting::Color as SyntectColor;
use crate::bat::terminal::to_ansi_color;
use crate::syntect_color;
-pub fn color_from_rgb_or_ansi_code(s: &str, true_color: bool) -> Color {
+pub fn parse_color(s: &str, true_color: bool) -> Option<Color> {
+ if s == "normal" {
+ return None;
+ }
let die = || {
eprintln!("Invalid color or style attribute: {}", s);
process::exit(1);
@@ -23,14 +26,7 @@ pub fn color_from_rgb_or_ansi_code(s: &str, true_color: bool) -> Color {
.or_else(|| syntect_color::syntect_color_from_ansi_name(s))
.unwrap_or_else(die)
};
- to_ansi_color(syntect_color, true_color)
-}
-
-pub fn color_from_rgb_or_ansi_code_with_default(arg: &str, true_color: bool) -> Option<Color> {
- match arg {
- "normal" => None,
- s => Some(color_from_rgb_or_ansi_code(s, true_color)),
- }
+ Some(to_ansi_color(syntect_color, true_color))
}
pub fn color_to_string(color: Color) -> String {