summaryrefslogtreecommitdiffstats
path: root/src/color.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/color.rs')
-rw-r--r--src/color.rs43
1 files changed, 14 insertions, 29 deletions
diff --git a/src/color.rs b/src/color.rs
index a4b96b58..d8b8a9f7 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -1,48 +1,39 @@
use std::collections::HashMap;
+use std::process;
use std::str::FromStr;
use ansi_term::Color;
use lazy_static::lazy_static;
use syntect::highlighting::Color as SyntectColor;
-use crate::fatal;
-use crate::git_config::GitConfig;
-use crate::utils;
+use crate::bat_utils::terminal::to_ansi_color;
+use crate::syntect_color;
-pub fn parse_color(s: &str, true_color: bool, git_config: Option<&GitConfig>) -> Option<Color> {
+pub fn parse_color(s: &str, true_color: bool) -> Option<Color> {
if s == "normal" {
return None;
}
let die = || {
- fatal(format!("Invalid color or style attribute: {s}"));
+ eprintln!("Invalid color or style attribute: {}", s);
+ process::exit(1);
};
let syntect_color = if s.starts_with('#') {
SyntectColor::from_str(s).unwrap_or_else(|_| die())
} else {
- let syntect_color = s
- .parse::<u8>()
+ s.parse::<u8>()
.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));
- if syntect_color.is_none() {
- if let Some(git_config) = git_config {
- if let Some(val) = git_config.get::<String>(&format!("delta.{s}")) {
- return parse_color(&val, true_color, None);
- }
- }
- die();
- }
- syntect_color.unwrap()
+ .and_then(syntect_color::syntect_color_from_ansi_number)
+ .or_else(|| syntect_color::syntect_color_from_ansi_name(s))
+ .unwrap_or_else(die)
};
- utils::bat::terminal::to_ansi_color(syntect_color, true_color)
+ Some(to_ansi_color(syntect_color, true_color))
}
pub fn color_to_string(color: Color) -> String {
match color {
Color::Fixed(n) if n < 16 => ansi_16_color_number_to_name(n).unwrap().to_string(),
- Color::Fixed(n) => format!("{n}"),
- Color::RGB(r, g, b) => format!("\"#{r:02x?}{g:02x?}{b:02x?}\""),
+ Color::Fixed(n) => format!("{}", n),
+ Color::RGB(r, g, b) => format!("\"#{:02x?}{:02x?}{:02x?}\"", r, g, b),
Color::Black => "black".to_string(),
Color::Red => "red".to_string(),
Color::Green => "green".to_string(),
@@ -99,7 +90,7 @@ pub fn ansi_16_color_name_to_number(name: &str) -> Option<u8> {
fn ansi_16_color_number_to_name(n: u8) -> Option<&'static str> {
for (k, _n) in &*ANSI_16_COLORS {
if *_n == n {
- return Some(*k);
+ return Some(&*k);
}
}
None
@@ -172,9 +163,3 @@ const DARK_THEME_PLUS_COLOR_256: Color = Color::Fixed(22);
const DARK_THEME_PLUS_EMPH_COLOR: Color = Color::RGB(0x00, 0x60, 0x00);
const DARK_THEME_PLUS_EMPH_COLOR_256: Color = Color::Fixed(28);
-
-// blame
-
-pub const LIGHT_THEME_BLAME_PALETTE: &[&str] = &["#FFFFFF", "#DDDDDD", "#BBBBBB"];
-
-pub const DARK_THEME_BLAME_PALETTE: &[&str] = &["#000000", "#222222", "#444444"];