summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-11-22 13:32:13 -0500
committerDan Davison <dandavison7@gmail.com>2021-11-22 18:12:36 -0500
commitf54bde760667350347ab050b332ab0c322729be2 (patch)
treec9fd089c97254e95a6ac983bbca35cd8cd911e57
parent22ad2bcad5e20e698b212ea526da41d7fc00efec (diff)
Show colors subcommand
Color groups from https://www.w3schools.com/colors/colors_groups.asp
-rw-r--r--src/cli.rs5
-rw-r--r--src/colors.rs213
-rw-r--r--src/main.rs4
-rw-r--r--src/options/set.rs1
-rw-r--r--src/subcommands/mod.rs1
-rw-r--r--src/subcommands/show_colors.rs73
6 files changed, 297 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index fdf54138..9f4a18cf 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -294,6 +294,11 @@ pub struct Opt {
#[structopt(long = "show-themes")]
pub show_themes: bool,
+ /// Show available named colors. In addition to named colors, arbitrary
+ /// colors can be specified using RGB hex codes. See COLORS section.
+ #[structopt(long = "show-colors")]
+ pub show_colors: bool,
+
#[structopt(long = "no-gitconfig")]
/// Do not take any settings from git config. See GIT CONFIG section.
pub no_gitconfig: bool,
diff --git a/src/colors.rs b/src/colors.rs
new file mode 100644
index 00000000..00e826a1
--- /dev/null
+++ b/src/colors.rs
@@ -0,0 +1,213 @@
+use std::collections::HashMap;
+
+pub fn color_groups() -> HashMap<String, Vec<(String, String)>> {
+ [
+ (
+ "Blue",
+ vec![
+ ("cadetblue", "#5f9ea0"),
+ ("steelblue", "#4682b4"),
+ ("lightsteelblue", "#b0c4de"),
+ ("lightblue", "#add8e6"),
+ ("powderblue", "#b0e0e6"),
+ ("lightskyblue", "#87cefa"),
+ ("skyblue", "#87ceeb"),
+ ("cornflowerblue", "#6495ed"),
+ ("deepskyblue", "#00bfff"),
+ ("dodgerblue", "#1e90ff"),
+ ("royalblue", "#4169e1"),
+ ("blue", "#0000ff"),
+ ("mediumblue", "#0000cd"),
+ ("darkblue", "#00008b"),
+ ("navy", "#000080"),
+ ("midnightblue", "#191970"),
+ ],
+ ),
+ (
+ "Brown",
+ vec![
+ ("cornsilk", "#fff8dc"),
+ ("blanchedalmond", "#ffebcd"),
+ ("bisque", "#ffe4c4"),
+ ("navajowhite", "#ffdead"),
+ ("wheat", "#f5deb3"),
+ ("burlywood", "#deb887"),
+ ("tan", "#d2b48c"),
+ ("rosybrown", "#bc8f8f"),
+ ("sandybrown", "#f4a460"),
+ ("goldenrod", "#daa520"),
+ ("darkgoldenrod", "#b8860b"),
+ ("peru", "#cd853f"),
+ ("chocolate", "#d2691e"),
+ ("olive", "#808000"),
+ ("saddlebrown", "#8b4513"),
+ ("sienna", "#a0522d"),
+ ("brown", "#a52a2a"),
+ ("maroon", "#800000"),
+ ],
+ ),
+ (
+ "Cyan",
+ vec![
+ ("aqua", "#00ffff"),
+ ("cyan", "#00ffff"),
+ ("lightcyan", "#e0ffff"),
+ ("paleturquoise", "#afeeee"),
+ ("aquamarine", "#7fffd4"),
+ ("turquoise", "#40e0d0"),
+ ("mediumturquoise", "#48d1cc"),
+ ("darkturquoise", "#00ced1"),
+ ],
+ ),
+ (
+ "Green",
+ vec![
+ ("greenyellow", "#adff2f"),
+ ("chartreuse", "#7fff00"),
+ ("lawngreen", "#7cfc00"),
+ ("lime", "#00ff00"),
+ ("limegreen", "#32cd32"),
+ ("palegreen", "#98fb98"),
+ ("lightgreen", "#90ee90"),
+ ("mediumspringgreen", "#00fa9a"),
+ ("springgreen", "#00ff7f"),
+ ("mediumseagreen", "#3cb371"),
+ ("seagreen", "#2e8b57"),
+ ("forestgreen", "#228b22"),
+ ("green", "#008000"),
+ ("darkgreen", "#006400"),
+ ("yellowgreen", "#9acd32"),
+ ("olivedrab", "#6b8e23"),
+ ("darkolivegreen", "#556b2f"),
+ ("mediumaquamarine", "#66cdaa"),
+ ("darkseagreen", "#8fbc8f"),
+ ("lightseagreen", "#20b2aa"),
+ ("darkcyan", "#008b8b"),
+ ("teal", "#008080"),
+ ],
+ ),
+ (
+ "Grey",
+ vec![
+ ("gainsboro", "#dcdcdc"),
+ ("lightgray", "#d3d3d3"),
+ ("silver", "#c0c0c0"),
+ ("darkgray", "#a9a9a9"),
+ ("dimgray", "#696969"),
+ ("gray", "#808080"),
+ ("lightslategray", "#778899"),
+ ("slategray", "#708090"),
+ ("darkslategray", "#2f4f4f"),
+ ("black", "#000000"),
+ ],
+ ),
+ (
+ "Orange",
+ vec![
+ ("orange", "#ffa500"),
+ ("darkorange", "#ff8c00"),
+ ("coral", "#ff7f50"),
+ ("tomato", "#ff6347"),
+ ("orangered", "#ff4500"),
+ ],
+ ),
+ (
+ "Pink",
+ vec![
+ ("pink", "#ffc0cb"),
+ ("lightpink", "#ffb6c1"),
+ ("hotpink", "#ff69b4"),
+ ("deeppink", "#ff1493"),
+ ("palevioletred", "#db7093"),
+ ("mediumvioletred", "#c71585"),
+ ],
+ ),
+ (
+ "Purple",
+ vec![
+ ("lavender", "#e6e6fa"),
+ ("thistle", "#d8bfd8"),
+ ("plum", "#dda0dd"),
+ ("orchid", "#da70d6"),
+ ("violet", "#ee82ee"),
+ ("fuchsia", "#ff00ff"),
+ ("magenta", "#ff00ff"),
+ ("mediumorchid", "#ba55d3"),
+ ("darkorchid", "#9932cc"),
+ ("darkviolet", "#9400d3"),
+ ("blueviolet", "#8a2be2"),
+ ("darkmagenta", "#8b008b"),
+ ("purple", "#800080"),
+ ("mediumpurple", "#9370db"),
+ ("mediumslateblue", "#7b68ee"),
+ ("slateblue", "#6a5acd"),
+ ("darkslateblue", "#483d8b"),
+ ("rebeccapurple", "#663399"),
+ ("indigo", "#4b0082"),
+ ],
+ ),
+ (
+ "Red",
+ vec![
+ ("lightsalmon", "#ffa07a"),
+ ("salmon", "#fa8072"),
+ ("darksalmon", "#e9967a"),
+ ("lightcoral", "#f08080"),
+ ("indianred", "#cd5c5c"),
+ ("crimson", "#dc143c"),
+ ("red", "#ff0000"),
+ ("firebrick", "#b22222"),
+ ("darkred", "#8b0000"),
+ ],
+ ),
+ (
+ "White",
+ vec![
+ ("white", "#ffffff"),
+ ("snow", "#fffafa"),
+ ("honeydew", "#f0fff0"),
+ ("mintcream", "#f5fffa"),
+ ("azure", "#f0ffff"),
+ ("aliceblue", "#f0f8ff"),
+ ("ghostwhite", "#f8f8ff"),
+ ("whitesmoke", "#f5f5f5"),
+ ("seashell", "#fff5ee"),
+ ("beige", "#f5f5dc"),
+ ("oldlace", "#fdf5e6"),
+ ("floralwhite", "#fffaf0"),
+ ("ivory", "#fffff0"),
+ ("antiquewhite", "#faebd7"),
+ ("linen", "#faf0e6"),
+ ("lavenderblush", "#fff0f5"),
+ ("mistyrose", "#ffe4e1"),
+ ],
+ ),
+ (
+ "Yellow",
+ vec![
+ ("gold", "#ffd700"),
+ ("yellow", "#ffff00"),
+ ("lightyellow", "#ffffe0"),
+ ("lemonchiffon", "#fffacd"),
+ ("lightgoldenrodyellow", "#fafad2"),
+ ("papayawhip", "#ffefd5"),
+ ("moccasin", "#ffe4b5"),
+ ("peachpuff", "#ffdab9"),
+ ("palegoldenrod", "#eee8aa"),
+ ("khaki", "#f0e68c"),
+ ("darkkhaki", "#bdb76b"),
+ ],
+ ),
+ ]
+ .iter()
+ .map(|(name, colors)| {
+ (
+ name.to_string(),
+ colors
+ .iter()
+ .map(|(color, hex)| (color.to_string(), hex.to_string()))
+ .collect(),
+ )
+ })
+ .collect()
+}
diff --git a/src/main.rs b/src/main.rs
index 95bd397a..3bea6098 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ mod align;
mod ansi;
mod cli;
mod color;
+mod colors;
mod config;
mod delta;
mod edits;
@@ -93,6 +94,9 @@ fn run_app() -> std::io::Result<i32> {
} else if opt.show_themes {
subcommands::show_themes::show_themes(opt.dark, opt.light, opt.computed.is_light_mode)?;
return Ok(0);
+ } else if opt.show_colors {
+ subcommands::show_colors::show_colors()?;
+ return Ok(0);
}
let _show_config = opt.show_config;
diff --git a/src/options/set.rs b/src/options/set.rs
index 8bd01508..faa2398b 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -186,6 +186,7 @@ pub fn set_options(
plus_non_emph_style,
raw,
relative_paths,
+ show_colors,
show_themes,
side_by_side,
wrap_max_lines,
diff --git a/src/subcommands/mod.rs b/src/subcommands/mod.rs
index f115910f..7669375e 100644
--- a/src/subcommands/mod.rs
+++ b/src/subcommands/mod.rs
@@ -1,6 +1,7 @@
pub mod diff;
pub mod list_syntax_themes;
mod sample_diff;
+pub mod show_colors;
pub mod show_config;
pub mod show_syntax_themes;
pub mod show_themes;
diff --git a/src/subcommands/show_colors.rs b/src/subcommands/show_colors.rs
new file mode 100644
index 00000000..fd194377
--- /dev/null
+++ b/src/subcommands/show_colors.rs
@@ -0,0 +1,73 @@
+use crate::cli;
+use crate::color;
+use crate::colors;
+use crate::config;
+use crate::delta;
+use crate::git_config;
+use crate::paint;
+use crate::paint::BgShouldFill;
+use crate::style;
+use crate::utils::bat::assets::HighlightingAssets;
+use crate::utils::bat::output::{OutputType, PagingMode};
+
+#[cfg(not(tarpaulin_include))]
+pub fn show_colors() -> std::io::Result<()> {
+ use itertools::Itertools;
+
+ let assets = HighlightingAssets::new();
+ let opt = cli::Opt::from_args_and_git_config(git_config::GitConfig::try_create(), assets);
+ let config = config::Config::from(opt);
+
+ let mut output_type =
+ OutputType::from_mode(PagingMode::QuitIfOneScreen, None, &config).unwrap();
+ let writer = output_type.handle().unwrap();
+
+ let mut painter = paint::Painter::new(writer, &config);
+ painter.set_syntax(Some("ts"));
+ painter.set_highlighter();
+
+ let title_style = ansi_term::Style::new().bold();
+ let mut style = style::Style {
+ is_syntax_highlighted: true,
+ ..style::Style::default()
+ };
+ for (group, color_names) in colors::color_groups().iter().sorted() {
+ writeln!(painter.writer, "\n\n{}\n", title_style.paint(group))?;
+ for (color_name, hex) in color_names {
+ // Two syntax-highlighted lines without background color
+ style.ansi_term_style.background = None;
+ for line in [
+ r#"export function color(): string {{ return "none" }}"#,
+ r#"export function hex(): string {{ return "none" }}"#,
+ ] {
+ painter.syntax_highlight_and_paint_line(
+ line,
+ paint::StyleSectionSpecifier::Style(style),
+ delta::State::HunkZero,
+ BgShouldFill::default(),
+ )
+ }
+ // Two syntax-highlighted lines with background color
+ let color =
+ color::parse_color(color_name, config.true_color, config.git_config.as_ref())
+ .unwrap();
+ style.ansi_term_style.background = Some(color);
+ for line in [
+ &format!(
+ r#"export function color(): string {{ return "{}" }}"#,
+ color_name
+ ),
+ &format!(r#"export function hex(): string {{ return "{}" }}"#, hex),
+ ] {
+ painter.syntax_highlight_and_paint_line(
+ line,
+ paint::StyleSectionSpecifier::Style(style),
+ delta::State::HunkZero,
+ BgShouldFill::default(),
+ )
+ }
+ painter.emit()?;
+ }
+ }
+ Ok(())
+}