summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cli.rs12
-rw-r--r--src/color.rs15
-rw-r--r--src/config.rs4
-rw-r--r--src/main.rs71
-rw-r--r--src/style.rs20
5 files changed, 91 insertions, 31 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 49caad24..01aa0fba 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -384,13 +384,11 @@ pub struct Opt {
#[structopt(long = "tabs", default_value = "4")]
pub tab_width: usize,
- /// Show the command-line arguments (RGB hex codes) for the background colors that are in
- /// effect. The hex codes are displayed with their associated background color. This option can
- /// be combined with --light and --dark to view the background colors for those modes. It can
- /// also be used to experiment with different RGB hex codes by combining this option with style
- /// options such as --minus-style, --zero-style, --plus-style, etc.
- #[structopt(long = "show-background-colors")]
- pub show_background_colors: bool,
+ /// Print the style strings for all style options. This can be used to experiment with
+ /// different colors by combining this option with other options such as --minus-style,
+ /// --zero-style, --plus-style, --light, --dark, etc.
+ #[structopt(long = "show-styles")]
+ pub show_styles: bool,
/// List supported languages and associated file extensions.
#[structopt(long = "list-languages")]
diff --git a/src/color.rs b/src/color.rs
index 8caaf4c4..463bfc22 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -39,6 +39,21 @@ pub fn color_from_rgb_or_ansi_code_with_default(
}
}
+pub fn color_to_string(color: Color) -> String {
+ match color {
+ 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(),
+ Color::Yellow => "yellow".to_string(),
+ Color::Blue => "blue".to_string(),
+ Color::Purple => "purple".to_string(),
+ Color::Cyan => "cyan".to_string(),
+ Color::White => "white".to_string(),
+ }
+}
+
// See
// https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
pub fn ansi_color_name_to_number(name: &str) -> Option<u8> {
diff --git a/src/config.rs b/src/config.rs
index 97b03645..abe746cb 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -61,7 +61,7 @@ pub struct Config {
pub plus_file: Option<PathBuf>,
pub plus_non_emph_style: Style,
pub plus_style: Style,
- pub show_background_colors: bool,
+ pub show_styles: bool,
pub line_numbers: bool,
pub syntax_dummy_theme: SyntaxTheme,
pub syntax_set: SyntaxSet,
@@ -225,7 +225,7 @@ impl From<cli::Opt> for Config {
plus_file: opt.plus_file.map(|s| s.clone()),
plus_non_emph_style,
plus_style,
- show_background_colors: opt.show_background_colors,
+ show_styles: opt.show_styles,
line_numbers: opt.line_numbers,
syntax_dummy_theme,
syntax_set: assets.syntax_set,
diff --git a/src/main.rs b/src/main.rs
index c24598fe..da2a28e2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -30,7 +30,7 @@ use std::io::{self, ErrorKind, Read, Write};
use std::path::PathBuf;
use std::process;
-use ansi_term::{self, Color};
+use ansi_term;
use atty;
use bytelines::ByteLinesReader;
use structopt::StructOpt;
@@ -62,8 +62,8 @@ fn main() -> std::io::Result<()> {
} else if config.list_syntax_themes {
list_syntax_themes()?;
process::exit(0);
- } else if config.show_background_colors {
- show_background_colors(&config);
+ } else if config.show_styles {
+ show_styles(&config);
process::exit(0);
} else if atty::is(atty::Stream::Stdin) {
return diff(
@@ -120,25 +120,52 @@ fn diff(
Ok(())
}
-fn show_background_colors(config: &config::Config) {
- println!(
- "delta \
- --minus-color=\"{minus_color}\" \
- --minus-emph-color=\"{minus_emph_color}\" \
- --plus-color=\"{plus_color}\" \
- --plus-emph-color=\"{plus_emph_color}\"",
- minus_color =
- get_painted_rgb_string(config.minus_style.ansi_term_style.background.unwrap()),
- minus_emph_color =
- get_painted_rgb_string(config.minus_emph_style.ansi_term_style.background.unwrap()),
- plus_color = get_painted_rgb_string(config.plus_style.ansi_term_style.background.unwrap()),
- plus_emph_color =
- get_painted_rgb_string(config.plus_emph_style.ansi_term_style.background.unwrap()),
- )
-}
-
-fn get_painted_rgb_string(color: Color) -> String {
- color.paint(format!("{:?}", color)).to_string()
+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}",
+ minus_style = config.minus_style.to_painted_string(),
+ zero_style = config.zero_style.to_painted_string(),
+ plus_style = config.plus_style.to_painted_string(),
+ minus_emph_style = config.minus_emph_style.to_painted_string(),
+ minus_non_emph_style = config.minus_non_emph_style.to_painted_string(),
+ plus_emph_style = config.plus_emph_style.to_painted_string(),
+ plus_non_emph_style = config.plus_non_emph_style.to_painted_string(),
+ commit_style = config.commit_style.to_painted_string(),
+ file_style = config.file_style.to_painted_string(),
+ hunk_header_style = config.hunk_header_style.to_painted_string(),
+ minus_empty_line_marker_style = config.minus_empty_line_marker_style.to_painted_string(),
+ plus_empty_line_marker_style = config.plus_empty_line_marker_style.to_painted_string(),
+ whitespace_error_style = config.whitespace_error_style.to_painted_string(),
+ );
+ 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 = 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(),
+ line_numbers_left_style = config.line_numbers_left_style.to_painted_string(),
+ line_numbers_right_style = config.line_numbers_right_style.to_painted_string(),
+ )
+ }
+ println!();
}
fn list_syntax_themes() -> std::io::Result<()> {
diff --git a/src/style.rs b/src/style.rs
index cf50f9db..dbac0863 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -3,6 +3,8 @@ use std::fmt;
use ansi_term;
+use crate::color;
+
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Style {
pub ansi_term_style: ansi_term::Style,
@@ -68,4 +70,22 @@ impl Style {
DecorationStyle::NoDecoration => None,
}
}
+
+ pub fn to_painted_string(&self) -> ansi_term::ANSIGenericString<str> {
+ self.paint(self.to_string())
+ }
+
+ 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())
+ )
+ }
}