Skip to content

Commit

Permalink
Merge pull request #29 from Aloso/dev
Browse files Browse the repository at this point in the history
Update docs, support percent value input
  • Loading branch information
Aloso authored Nov 4, 2020
2 parents 6023301 + 1ead35f commit bbdee76
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 171 deletions.
118 changes: 0 additions & 118 deletions Color spaces.md

This file was deleted.

30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,21 @@ If `colo` is used outside of a terminal, it outputs the color as text. The forma

### Supported color spaces

| Name | Description | Range of values |
|-------------|------------------------------------|-----------------|
| `rgb` | red, green, blue | 0 to 255 |
| `cmy` | cyan, magenta, yellow | 0 to 1 |
| `cmyk` | cyan, magenta, yellow, key | 0 to 1 |
| `hsv` | hue, saturation, value | hue: 0 to 360, saturation: 0 to 1, value: 0 to 1 |
| `hsl` | hue, saturation, light | hue: 0 to 360, saturation: 0 to 1, light: 0 to 1 |
| `lch` | luminance, chroma, hue | luminance: 0 to 100, chroma: 0 to 100, hue: 0 to 360 |
| `luv` | CIELUV color (luminance, u, v) | luminance: 0 to 100, u: -134 to 220, v: -140 to 122 |
| `lab` | CIELAB color (lightness, a, b) | lightness: 0 to 100, a: ??, b: ?? |
| `hunterlab` | Hunter Lab color (lightness, a, b) | lightness: 0 to 100, a: ??, b: ?? |
| `xyz` | CIE 1931 XYZ color | ?? |
| `yxy` | CIE YXY color | ?? |
Read in more detail about these color spaces [here](https://aloso.github.io/colo/color_spaces#srgb-rgb).

| Name | Description | Range of values |
|-------------|---------------------------------|---------------------|
| `rgb` | red, green, blue | 0 to 255 |
| `cmy` | cyan, magenta, yellow | 0 to 1 |
| `cmyk` | cyan, magenta, yellow, key | 0 to 1 |
| `hsl` | hue, saturation, light | hue: 0 to 360, saturation: 0 to 1, light: 0 to 1 |
| `hsv` | hue, saturation, value | hue: 0 to 360, saturation: 0 to 1, value: 0 to 1 |
| `lab` | CIELAB (lightness, a, b) | lightness: 0 to 100 |
| `lch` | CIELCh (luminance, chroma, hue) | luminance: 0 to 100, chroma: 0 to 100, hue: 0 to 360 |
| `luv` | CIELUV (luminance, u, v) | luminance: 0 to 100, u: -134 to 220, v: -140 to 122 |
| `hunterlab` | Hunter Lab (lightness, a, b) | lightness: 0 to 100 |
| `xyz` | CIE XYZ (x, lightness, z) | lightness: 0 to 100 |
| `yxy` | CIE Yxy (lightness, x, y) | lightness: 0 to 100 |

### Specifying hexadecimal colors

Expand Down Expand Up @@ -129,8 +131,6 @@ Also, to pass continuous integration, the code must
* compile on the latest stable Rust version
* all tests must succeed

Note: I'm currently refactoring the code base, so this is a bad time for large pull requests. I should be finished with this in a week at the latest.

You can also look in the issue tracker for issues with the label [help wanted](https://github.com/Aloso/colo/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22).

That's it! If you have any questions, feel free to create an issue.
Binary file removed docs/colors/black.png
Binary file not shown.
Binary file removed docs/colors/blue.png
Binary file not shown.
Binary file removed docs/colors/cyan.png
Binary file not shown.
Binary file removed docs/colors/green.png
Binary file not shown.
Binary file removed docs/colors/magenta.png
Binary file not shown.
Binary file removed docs/colors/red.png
Binary file not shown.
Binary file removed docs/colors/white.png
Binary file not shown.
Binary file removed docs/colors/yellow.png
Binary file not shown.
41 changes: 6 additions & 35 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,14 @@ const COLOR_FORMATS: &[&str] = &[
"hex",
];

macro_rules! color_help_message {
() => {
"\
const COLOR_HELP_MESSAGE: &str = "\
The input colors. Multiple colors can be specified. Supported formats:
* HTML color name (e.g. 'rebeccapurple')
* Hexadecimal RGB color (e.g. '07F', '0077FF')
* Color components (e.g. '127, 0, 255', 'hsl(30, 1, .5)').
If no color space is specified, it defaults to 'rgb'.
Commas and parentheses are optional."
};
}

macro_rules! color_space_help {
() => {
"\
Supported color spaces
======================
name arguments values
-------------------------------------------------------------------
rgb red, green, blue 0-255 0-255 0-255
cmy cyan, magenta, yellow 0-1 0-1 0-1
cmyk cyan, magenta, yellow, key 0-1 0-1 0-1 0-1
hsv hue, saturation, value 0-360 0-1 0-1
hsl hue, saturation, light 0-360 0-1 0-1
lch luminance, chroma, hue 0-100 0-100 0-360
luv luminance, u, v (CIELUV) 0-100 –134-220 –140-122
lab lightness, a, b (CIELAB) 0-100 ? ?
hunterlab lightness, a, b (CIELAB) 0-100 ? ?
xyz x,y,z (CIE 1931 XYZ color) ? ? ?
yxy y1,x,y2 (CIE YXY color) ? ? ?"
};
}

const COLOR_HELP_LONG_MESSAGE: &str = concat!(color_help_message!(), "\n\n", color_space_help!());

const COLOR_HELP_MESSAGE: &str = color_help_message!();
* HTML color name, e.g. 'rebeccapurple'
* Hexadecimal RGB color, e.g. '07F', '0077FF'
* Color components, e.g. 'hsl(30, 100%, 50%)'
Commas and parentheses are optional.
For supported color spaces, see <https://aloso.github.io/colo/color_spaces>";

/// Returns the command line arguments parsed by clap.
///
Expand Down
1 change: 0 additions & 1 deletion src/cli/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn command<'a, 'b>() -> App<'a, 'b> {
.takes_value(true)
.required(false)
.help(super::COLOR_HELP_MESSAGE)
.long_help(super::COLOR_HELP_LONG_MESSAGE)
.multiple(true)
.use_delimiter(false),
Arg::with_name("OUTPUT_FORMAT")
Expand Down
10 changes: 8 additions & 2 deletions src/color/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ pub fn parse(mut input: &str) -> Result<Vec<(Color, ColorFormat)>, ParseError> {
let (n, input_ii) = parse_number(input_i)?.ok_or_else(|| MissingFloat {
got: input_i.into(),
})?;
*num = n;
input_i = input_ii;
input_i = input_ii.trim_start();

if input_i.starts_with('%') {
input_i = &input_i[1..];
*num = n / 100.0;
} else {
*num = n;
}
}

let nums = &nums[0..expected];
Expand Down

0 comments on commit bbdee76

Please sign in to comment.