diff options
-rw-r--r-- | src/color.rs | 10 | ||||
-rw-r--r-- | src/main.rs | 38 | ||||
-rw-r--r-- | src/style.rs | 52 |
3 files changed, 70 insertions, 30 deletions
diff --git a/src/color.rs b/src/color.rs index 711b6aec..b19a8416 100644 --- a/src/color.rs +++ b/src/color.rs @@ -35,6 +35,7 @@ pub fn color_from_rgb_or_ansi_code_with_default(arg: &str, true_color: bool) -> 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!("#{:02x?}{:02x?}{:02x?}", r, g, b), Color::Black => "black".to_string(), @@ -90,6 +91,15 @@ pub fn ansi_16_color_name_to_number(name: &str) -> Option<u8> { ANSI_16_COLORS.get(name).map(|n| *n) } +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); + } + } + None +} + pub fn get_minus_background_color_default(is_light_mode: bool, is_true_color: bool) -> Color { match (is_light_mode, is_true_color) { (true, true) => LIGHT_THEME_MINUS_COLOR, diff --git a/src/main.rs b/src/main.rs index da2a28e2..26a383c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,19 +123,19 @@ fn diff( fn show_styles(config: &config::Config) { print!( "\ ---commit-style {commit_style} ---file-style {file_style} ---hunk-header-style {hunk_header_style} ---minus-style {minus_style} ---minus-non-emph-style {minus_non_emph_style} ---minus-emph-style {minus_emph_style} ---minus-empty-line-marker-style {minus_empty_line_marker_style} ---zero-style {zero_style} ---plus-style {plus_style} ---plus-non-emph-style {plus_non_emph_style} ---plus-emph-style {plus_emph_style} ---plus-empty-line-marker-style {plus_empty_line_marker_style} ---whitespace-error-style {whitespace_error_style}", +commit-style = {commit_style} +file-style = {file_style} +hunk-header-style = {hunk_header_style} +minus-style = {minus_style} +minus-non-emph-style = {minus_non_emph_style} +minus-emph-style = {minus_emph_style} +minus-empty-line-marker-style = {minus_empty_line_marker_style} +zero-style = {zero_style} +plus-style = {plus_style} +plus-non-emph-style = {plus_non_emph_style} +plus-emph-style = {plus_emph_style} +plus-empty-line-marker-style = {plus_empty_line_marker_style} +whitespace-error-style = {whitespace_error_style}", minus_style = config.minus_style.to_painted_string(), zero_style = config.zero_style.to_painted_string(), plus_style = config.plus_style.to_painted_string(), @@ -152,12 +152,12 @@ fn show_styles(config: &config::Config) { ); if config.line_numbers { print!( - "\ ---line-numbers-minus-style {line_numbers_minus_style} ---line-numbers-zero-style {line_numbers_zero_style} ---line-numbers-plus-style {line_numbers_plus_style} ---line-numbers-left-style {line_numbers_left_style} ---line-numbers-right-style {line_numbers_right_style}", + " +line-numbers-minus-style = {line_numbers_minus_style} +line-numbers-zero-style = {line_numbers_zero_style} +line-numbers-plus-style = {line_numbers_plus_style} +line-numbers-left-style = {line_numbers_left_style} +line-numbers-right-style = {line_numbers_right_style}", line_numbers_minus_style = config.line_numbers_minus_style.to_painted_string(), line_numbers_zero_style = config.line_numbers_zero_style.to_painted_string(), line_numbers_plus_style = config.line_numbers_plus_style.to_painted_string(), diff --git a/src/style.rs b/src/style.rs index 734d3b9f..990e910b 100644 --- a/src/style.rs +++ b/src/style.rs @@ -90,16 +90,46 @@ impl Style { } fn to_string(&self) -> String { - format!( - "{} {}", - self.ansi_term_style - .foreground - .map(color::color_to_string) - .unwrap_or("normal".to_string()), - self.ansi_term_style - .background - .map(color::color_to_string) - .unwrap_or("".to_string()) - ) + if self.is_raw { + return "raw".to_string(); + } + let mut words = Vec::<String>::new(); + if self.is_omitted { + words.push("omit".to_string()); + } + if self.ansi_term_style.is_blink { + words.push("blink".to_string()); + } + if self.ansi_term_style.is_bold { + words.push("bold".to_string()); + } + if self.ansi_term_style.is_dimmed { + words.push("dim".to_string()); + } + if self.ansi_term_style.is_italic { + words.push("italic".to_string()); + } + if self.ansi_term_style.is_reverse { + words.push("reverse".to_string()); + } + if self.ansi_term_style.is_strikethrough { + words.push("strike".to_string()); + } + if self.ansi_term_style.is_underline { + words.push("ul".to_string()); + } + + match (self.is_syntax_highlighted, self.ansi_term_style.foreground) { + (true, _) => words.push("syntax".to_string()), + (false, Some(color)) => { + words.push(color::color_to_string(color)); + } + (false, None) => words.push("normal".to_string()), + } + match self.ansi_term_style.background { + Some(color) => words.push(color::color_to_string(color)), + None => {} + } + words.join(" ") } } |