Skip to content

Commit

Permalink
Change approx name suffix to '~' and add missing dependency for Pytho…
Browse files Browse the repository at this point in the history
…n 3.6
  • Loading branch information
joowani committed Jan 24, 2021
1 parent 63a1d86 commit 412c3b1
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 12 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md LICENSE
prune tests
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Command-line tool for quickly looking up colors, shades and palettes.
Supported [color models](https://en.wikipedia.org/wiki/Color_model):
HEX, RGB, HSL, HSV, CMYK

![](example.gif)
![](demo.gif)

![Build](https://github.com/joowani/colorpedia/workflows/Build/badge.svg?branch=main)
![CodeQL](https://github.com/joowani/colorpedia/workflows/CodeQL/badge.svg)
Expand Down Expand Up @@ -103,8 +103,8 @@ The command above creates `~/.config/colorpedia/config.json` with default settin
{
// Always display in JSON format. Use with --nojson flag.
"always_output_json": false,
// Suffix for approximate color names (e.g. "green (approx)").
"approx_name_suffix": " (approx)",
// Suffix for approximate color names (e.g. "green~").
"approx_name_suffix": "~",
// Default number of shades displayed when --shades is used without a count.
"default_shades_count": 15,
// Display degrees angle (°) symbol. Use with --nounits flag.
Expand Down Expand Up @@ -164,15 +164,30 @@ color rgb --help
color palette --help
```


### Technical Notes
- Names of "unknown" colors are approximated using minimum RGB delta:
```
delta = (R1 - R2) ^ 2 + (G1 - G2) ^ 2 + (B1 - B2) ^ 2
```
If there is are ties, all names are included in the output using `/` delimiter.
If there is are ties, all names are included in the output.
- Percentage values use 0 - 100 scale by default, 0 - 1 scale in JSON.
- Degree angles use 0 - 360 scale by default, 0 - 1 scale in JSON.
- Percent and degree unit symbols are omitted in JSON.
- If HSV/HSL/CMYK values do not map exactly to an RGB triplet, they are
rounded to the nearest one.


### Contributing

To set up dev environment:

```shell
cd ~/your/colorpedia/clone # Activate venv if you have one
pip install -e .[dev] # Install dev dependencies (black, mypy, pre-commit etc.)
pre-commit install # Install git pre-commit hooks
```

To run unit tests:
```shell
py.test
```
2 changes: 1 addition & 1 deletion colorpedia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@dataclass
class Config:
always_output_json: bool = False
approx_name_suffix: str = " (approx)"
approx_name_suffix: str = "~"
default_shades_count: int = DEFAULT_SHADES_COUNT
display_degree_symbol: bool = False
display_percent_symbol: bool = False
Expand Down
4 changes: 2 additions & 2 deletions colorpedia/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def validate_shades_count(value: Union[bool, int]) -> int:


def validate_editor(value: Optional[str]):
if value is None or (type(value) == str and len(value.split()) == 1):
if value is None or (type(value) == str and len(value) > 0 and " " not in value):
return value
raise InputValueError("editor", "a shell-executable command without args")
raise InputValueError("editor", "a shell-executable command without whitespaces")


def validate_rgb_value(value: int) -> int:
Expand Down
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example.gif
Binary file not shown.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
with open("README.md") as fp:
description = fp.read()


setup(
name="colorpedia",
license="MIT",
description="Command-line tool for looking up colors",
long_description=description,
long_description_content_type="text/markdown",
Expand All @@ -16,9 +14,11 @@
packages=find_packages(exclude=["tests"]),
include_package_data=True,
python_requires=">=3.6",
license="MIT",
use_scm_version=True,
setup_requires=["setuptools_scm"],
install_requires=[
"dataclasses",
"fire>=0.3.1",
"setuptools>=42",
"setuptools_scm[toml]>=3.4",
Expand All @@ -29,6 +29,7 @@
"flake8",
"isort>=5.0.0",
"mypy",
"pre-commit",
"pytest>=6.0.0",
"pytest-cov>=2.0.0",
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_format_rgb_with_units(r, g, b, expected):


def test_format_name():
assert format_name(default_config, "foo", False) == "foo (approx)"
assert format_name(default_config, "foo", False) == "foo~"
assert format_name(default_config, "foo", True) == "foo"
assert format_name(custom_config, "foo", False) == "foo*"
assert format_name(custom_config, "foo", True) == "foo"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_validate_editor_flag_bad_arg(bad_arg):
validate_editor(bad_arg)
assert (
str(err.value)
== "Bad editor (expecting a shell-executable command without args)"
== "Bad editor (expecting a shell-executable command without whitespaces)"
)


Expand Down

0 comments on commit 412c3b1

Please sign in to comment.