Skip to content

Commit

Permalink
add new option --list-named-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
mazznoer committed Jul 11, 2023
1 parent 8944fc3 commit 2050e57
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ atty = "0.2.14"
clap = { version = "4.3.8", features = ["derive", "wrap_help"] }
#colorgrad = "0.6.2"
colorgrad = { git = "https://github.com/mazznoer/colorgrad-rs.git", features = ["lab", "ggr"] }
csscolorparser = { git = "https://github.com/mazznoer/csscolorparser-rs.git" }
svg = "0.13.1"
terminal_size = "0.2.6"

Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ pub struct Opt {
/// Print colors from --take or --sample, as array
#[arg(short = 'a', long)]
pub array: bool,

/// Lists all CSS named colors
#[arg(long)]
pub list_named_colors: bool,
}

#[test]
Expand Down
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ impl GradientApp {
return Ok(0);
}

if self.opt.list_named_colors {
for (&name, &[r, g, b]) in csscolorparser::NAMED_COLORS.entries() {
writeln!(
self.stdout,
"\x1B[48;2;{r};{g};{b}m \x1B[49;38;2;{r};{g};{b}m #{r:02x}{g:02x}{b:02x}\x1B[39m {name}"
)?;
}

return Ok(0);
}

if self.opt.preset.is_some() {
return self.preset_gradient();
}
Expand Down

0 comments on commit 2050e57

Please sign in to comment.