Skip to content

Commit

Permalink
Add first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
joowani committed Jan 22, 2021
1 parent e966dd2 commit b75b79d
Show file tree
Hide file tree
Showing 30 changed files with 2,700 additions and 3 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]
jobs:
build:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
steps:
- uses: actions/checkout@v2
- name: Fetch complete history for all tags and branches
run: git fetch --prune --unshallow
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup pip
run: python -m pip install --upgrade pip setuptools wheel
- name: Install Colorpedia
run: pip install .[dev]
- name: Run black
run: black --check .
- name: Run flake8
run: flake8 .
- name: Run isort
run: isort --check --profile=black .
- name: Run mypy
run: mypy .
- name: Run pytest
run: py.test --cov=./ --cov-report=xml
- name: Run color
run: |
color version
color version --json
color config init
color config show
color name white
color hex FFFFFF
color rgb 255 255 255
color hsl 0 0 100
color hsv 0 0 100
color cmyk 0 0 0 0
color palette molokai
color name white --all
color hex FFFFFF --all
color rgb 255 255 255 --all
color hsl 0 0 100 --all
color hsv 0 0 100 --all
color cmyk 0 0 0 0 --all
color palette molokai --all
color name white --nounits
color hex FFFFFF --nounits
color rgb 255 255 255 --nounits
color hsl 0 0 100 --nounits
color hsv 0 0 100 --nounits
color cmyk 0 0 0 0 --nounits
color palette molokai --nounits
color name white --json
color hex FFFFFF --json
color rgb 255 255 255 --json
color hsl 0 0 100 --json
color hsv 0 0 100 --json
color cmyk 0 0 0 0 --json
color palette molokai --json
color name white --shades
color hex FFFFFF --shades
color rgb 255 255 255 --shades
color hsl 0 0 100 --shades
color hsv 0 0 100 --shades
color cmyk 0 0 0 0 --shades
- name: Upload coverge to Codecov
uses: codecov/codecov-action@v1
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8'
with:
token: ${{ secrets.CODECOV_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/codeql-anaylsis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CodeQL
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]
schedule:
- cron: '21 2 * * 3'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: 'python'
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
31 changes: 31 additions & 0 deletions .github/workflows/pypi-upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Upload to PyPI
on:
release:
types: [created]
jobs:
upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Fetch complete history for all tags and branches
run: git fetch --prune --unshallow
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine setuptools-scm[toml]
- name: Build distribution
run: python setup.py sdist bdist_wheel
- name: Publish to PyPI Test
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_TOKEN }}
run: twine upload --repository testpypi dist/*
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload --repository pypi dist/*
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ dmypy.json

# Pyre type checker
.pyre/

# Intellij
.idea/

# setuptools-scm
colorpedia/version.py
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/timothycrosley/isort
rev: 5.7.0
hooks:
- id: isort
args: [ --profile, black ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.790
hooks:
- id: mypy
args: [ --no-strict-optional, --ignore-missing-imports ]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Joohwan Oh
Copyright (c) 2021 Joohwan Oh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
175 changes: 173 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,173 @@
# colorpedia
Look up colors and color schemes.
## Colorpedia

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)

![Build](https://github.com/joowani/colorpedia/workflows/Build/badge.svg?branch=main)
![CodeQL](https://github.com/joowani/colorpedia/workflows/CodeQL/badge.svg)
[![Codecov](https://codecov.io/gh/joowani/colorpedia/branch/main/graph/badge.svg?token=EH6F62KWTB)](https://codecov.io/gh/joowani/colorpedia)


### Requirements

* Modern terminal with true color and utf-8 support
(e.g. Windows Terminal, PowerShell, iTerm2, Terminator)
* Python 3.6+

### Installation

Install via [pip](https://pip.pypa.io):

```shell
pip install colorpedia
```

Add the following line in .bashrc for autocompletion (only bash supported):

```shell
source <(color -- --completion)
```

Restart your shell to use the `color` command:

```shell
color --help
```

### Usage

Look up colors using various color models:

```shell
color name green # CSS3 color name
color hex FFFFFF # hex code without the hash (#) prefix
color rgb 255 255 255 # RGB (Red Green Blue)
color hsl 360 100 100 # HSL (Hue Saturation Lightness)
color hsv 360 100 100 # HSV (Hue Saturation Brightness)
color cmyk 100 100 100 100 # CMYK (Cyan Magenta Yellow Black)
```

Use `--shades` to display shades of a color (dark to light):

```shell
color name green --shades # Display 15 colors by default
color hex FFFFFF --shades=5 # Display 5 shades
```

Look up color palettes:

```shell
color palette molokai
color palette zenburn
color palette blue
color palette kelly
```

Control the output with global flags:

```shell
color name yellow --all # Display all details
color name yellow --json # Display in JSON format
color name yellow --units # Display unit symbols
color name yellow --nojson # Do not display in JSON
color name yellow --nounits # Do not display unit symbols
```

Combine with other tools like [jq](https://github.com/stedolan/jq):

```shell
color palette molokai | cut -d'|' -f 2,3,4
color name blue --range --json | jq .[0].name
```

### Configuration

Initialize the config file to customize CLI behavior:

```shell
color config init
```

The command above creates `~/.config/colorpedia/config.json` with default settings:

```json5
{
// 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)",
// Default number of shades displayed when --shades is used without a count.
"default_shades_count": 15,
// Display degrees angle (°) symbol. Use with --nounits flag.
"display_degree_symbol": false,
// Display percentage (%) symbol. Use with --nounits flag.
"display_percent_symbol": false,
// Height of the color box displayed in single-color (get) view.
"get_view_color_height": 10,
// Width of the color box displayed in single-color (get) view.
"get_view_color_width": 20,
// Keys displayed in single-color (get) view.
"get_view_keys": [
"rgb",
"cmyk",
"hex",
"name",
"color",
"hsl",
"hsv"
],
// Keys displayed in JSON view.
"json_keys": [
"rgb",
"cmyk",
"hex",
"is_name_exact",
"name",
"hsl",
"hsv"
],
// Width of the color box displayed in multi-color (list) view.
"list_view_color_width": 20,
// Keys displayed in multi-color (list) view.
"list_view_keys": [
"rgb",
"hex",
"name",
"color",
"hsv"
],
// Always uppercase hex codes if set to true, lowercase if set to false.
"uppercase_hex_codes": true
}
```

Handy shortcuts to view and edit the configuration file:

```shell
color config show # Display configuration
color config edit # Edit configuration via a text editor
```

Use `--help` to see more information on each subcommand:
```shell
color config --help
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.
- 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.
15 changes: 15 additions & 0 deletions colorpedia/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from colorpedia.color import Color
from colorpedia.converters import (
cmyk_to_rgb,
hex_to_rgb,
hsl_to_rgb,
hsl_to_rgb_shades,
hsv_to_rgb,
name_to_rgb,
palette_to_rgbs,
rgb_to_cmyk,
rgb_to_hex,
rgb_to_hsl,
rgb_to_hsv,
rgb_to_names,
)
Loading

0 comments on commit b75b79d

Please sign in to comment.