Git Product home page Git Product logo

pastel's Introduction

pastel

Build Status

pastel is a command-line tool to generate, analyze, convert and manipulate colors. It supports many different color formats and color spaces like RGB (sRGB), HSL, CIELAB, CIELCh as well as ANSI 8-bit and 24-bit representations.

In action

pastel in action

Tutorial

Getting help

pastel provides a number of commands like saturate, mix or paint. To see a complete list, you can simply run

pastel

To get more information about a specific subcommand (say mix), you can call pastel mix -h or pastel help mix.

Composition

Many pastel commands can be composed by piping the output of one command to another, for example:

pastel random | pastel mix red | pastel lighten 0.2 | pastel format hex

Specifying colors

Colors can be specified in many different formats:

lightslategray
'#778899'
778899
789
'rgb(119, 136, 153)'
'119,136,153'
'hsl(210, 14.3%, 53.3%)'

Colors can be passed as positional arguments, for example:

pastel lighten 0.2 orchid orange lawngreen

They can also be read from standard input. So this is equivalent:

printf "%s\n" orchid orange lawngreen | pastel lighten 0.2

You can also explicitly specify which colors you want to read from the input. For example, this mixes red (which is read from STDIN) with blue (which is passed on the command line):

pastel color red | pastel mix - blue

Use cases and demo

Converting colors from one format to another

pastel format hsl ff8000

Show and analyze colors on the terminal

pastel color "rgb(255,50,127)"

pastel color 556270 4ecdc4 c7f484 ff6b6b c44d58

Pick a color from somewhere on the screen

pastel pick

Generate a set of N visually distinct colors

pastel distinct 8

Get a list of all X11 / CSS color names

pastel list

Name a given color

pastel format name 44cc11

Print colorized text from a shell script

bg="hotpink"
fg="$(pastel textcolor "$bg")"

pastel paint "$fg" --on "$bg" "well readable text"
pastel paint -n black --on red --bold "   ERROR!   "
echo " A serious error"

pastel paint -n black --on yellow --bold "  WARNING!  "
echo " A warning message"

pastel paint -n black --on limegreen --bold "    INFO    "
echo -n " Informational message with a "
echo -n "highlighted" | pastel paint -n default --underline
echo " word"

Installation

On Debian-based systems

You can download the latest Debian package from the release page and install it via dpkg:

wget "https://github.com/sharkdp/pastel/releases/download/v0.8.1/pastel_0.8.1_amd64.deb"
sudo dpkg -i pastel_0.8.1_amd64.deb

On Arch Linux

You can install pastel from the Extra repositories:

sudo pacman -S pastel

On Nix

You can install pastel from the Nix package:

nix-env --install pastel

On MacOS

You can install pastel via Homebrew

brew install pastel

On Windows

You can install pastel via Scoop

scoop install pastel

With Winget

You can install pastel via Winget:

winget install sharkdp.pastel

Via snap package

Get it from the Snap Store:

sudo snap install pastel

On NetBSD

Using the package manager:

pkgin install pastel

From source:

cd /usr/pkgsrc/graphics/pastel
make install

On other distributions

Check out the release page for binary builds.

Via cargo (source)

If you do not have cargo, install using rust's installation documentation.

If you have Rust 1.43 or higher, you can install pastel from source via cargo:

cargo install pastel

Alternatively, you can install pastel directly from this repository by using

git clone https://github.com/sharkdp/pastel
cargo install --path ./pastel

Resources

Interesting Wikipedia pages:

Color names:

Maximally distinct colors:

Other articles and videos:

License

Licensed under either of

at your option.

pastel's People

Contributors

azdavis avatar bresilla avatar danieledapo avatar data-man avatar dependabot[bot] avatar divoolej avatar djmattyg007 avatar irevoire avatar joveian avatar kelsolaar avatar kianmeng avatar lzybkr avatar mforster avatar mrusme avatar musikid avatar purveshpatel511 avatar pvonmoradi avatar rashil2000 avatar rivy avatar rozbb avatar rwe avatar sharkdp avatar sigmasd avatar sitiom avatar sorairolake avatar superhawk610 avatar szepeviktor avatar technologyclassroom avatar yyzdtccjdtc avatar zica87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pastel's Issues

Add 'sort' subcommand

pastel random -n 20 | pastel sort --by luminance
pastel list | pastel sort --by chroma

Also, add a --reverse/-r flag.

Think about whether we still need the --sort option on pastel list.

Add 'compare' or 'difference' subcommand

Which computes contrast, color difference, etc.

in the interactive version, we could show a-colored text on a b-colored background. Also, show two color panels (like in pastel color) directly next to each other.

Strategy to handle terminals without 24bit support

We distinguish 3 modes:

  • no color
  • 8 bit mode (\x1b[38;5;167m)
  • 24 bit mode, aka "true color" (\x1b[38;2;255;0;127m)

Note that we ignore the 16-color ANSI mode, as we can't really predict how the 16 colors look like.

We choose the mode in the following way:

  • If --mode=24bit or --mode=8bit => use the given mode.
  • Otherwise, if the output goes to a non-interactive terminal => use no color mode
  • Otherwise, if PASTEL_MODE=8bit, use 8 bit mode
  • Otherwise, if PASTEL_MODE==24bit or COLORTERM==truecolor or COLORTERM==24bit => use 24 bit mode
  • Otherwise, use 8 bit mode and show a warning.

Further literature: https://gist.github.com/XVilka/8346728

Test on Windows

  • do we have to include the code to enable ANSI codes on Windows? This does not seem to be required on Windows 10?
  • Make sure that we don't show the "COLORTERM" warning. PowerShell is not going to set this for us.
  • pastel pick => any supported tools?

Use simple output format in non-interactive mode

In non-interactive mode, pastel should simply print the color as #rrggbb string in order to allow for things like this:

echo salmon | pastel darken 0.2 | pastel saturate 0.1

pastel darken 0.1 red | pastel mix RGB green | pastel saturate 0.1

'set' or 'modify' subcommand

For example

pastel random | pastel set luminance 0.4

we could even think about replacing saturate, lighten, etc. with:

pastel modify saturation +0.3
pastel set saturation 0.5
...

Allow "-" as color argument (= read from stdin)

.. this should work even if we are in interactive mode.

To do things like:

pastel darken 0.2 red

# okay, let's compare it to the original color:
pastel darken 0.2 red | pastel show red -

Add subcommands to work with ANSI colors

Provide a way to:

  • Show the 24-bit ANSI code for a given color
  • Show an approximated 8-bit ANSI code for a given color
  • (Show the best-matching ansi16 color)

Use cases:

pastel paint red "ERROR: ..."
pastel paint red --bold "ERROR: ..."
pastel paint black --on yellow "WARNING: ..."

pastel red | pastel lighten 0.2 | pastel paint - "ERROR: ..."

echo "$(pastel ansi salmon)colored text$(pastel ansi reset)"

Move regex compiles into lazy_static block to speed up parsing

Reading input is currently really slow:

▶ pastel random -n 1000 > colors
▶ hyperfine 'pastel format hex < colors'
Benchmark #1: pastel format hex < colors
  Time (mean ± σ):     313.8 ms ±   5.9 ms    [User: 309.8 ms, System: 3.5 ms]
  Range (min … max):   307.8 ms … 327.9 ms    10 runs

The main reason is that we compile the regexes in each iteration:
image

Add 'random' subcommand

There are many ways to generate random colors. Sampling uniformly in RGB space is probably not very interesting as it will likely produce a lot of dull, grayish and brownish colors.

Sampling in HSL space with a restricted range on saturation and lightness could be more interesting if we are interested in more vivid colors.

Using Lab or LCH space could be even better because we are now sampling "correctly" with respect to perceived color distances.

We could probably add an argument to the pastel random command for the sampling strategy.

Add README

Actual use cases:

  • Convert colors to a different format (pastel format hsl ff8000)
  • Quickly preview a given color (pastel color "rgb(255,50,127)")
  • Pick a color from a palette, show it in all kinds of different formats (pastel pick)
  • Pick a color somewhere from the screen (pastel pick)
  • Use pastel paint to print colorized text from shell scripts (with automatic mode detection) ==> actually try this (how to switch off colors?)!
  • Generate a distinct colors for a plot/map/... (pastel distinct -n 5)
  • Generate a gradient of colors (pastel gradient pick pick | pastel format hex)
  • Sample from a predefined color scale (pastel sample magma 0.3)

Some ideas for cool demos / snippets:

(see https://www.colourlovers.com/colors/most-loved/all-time/meta for some cool colors 😄)

# basics
pastel show 0077ff
# https://www.colourlovers.com/palette/1930/cheer_up_emo_kid
pastel color 556270 4ecdc4 c7f484 ff6b6b c44d58


pastel show salmon
pastel show salmon | pastel darken 0.2
pastel show salmon | pastel darken 0.2 | pastel desaturate 0.5

my_color=$(pastel show salmon | pastel darken 0.2 | pastel desaturate 0.5)

pastel show red blue green

pastel random
pastel random | pastel format
pastel random -n 30 | pastel sort-by hue | pastel format
pastel random -n 100 -s lch_hue | pastel sort-by hue | \
  xargs -L1 -I{} pastel paint black --on "{}" "        "

pastel random -s gray | pastel mix cyan | pastel format

(pastel gradient ffffcc fd8d3c;
 pastel gradient fd8d3c 800026) | \
  xargs -L1 -I{} pastel paint black --on "{}" "  " -n
echo


pastel gradient -n 20 -s hsl pick pick  | pastel format hex


bg="hotpink"
fg="$(pastel textcolor "$bg")"

pastel paint "$fg" --on "$bg" "well readable text"

Integration with other Unix tools:

  • seq:
    LANG=en seq 0 0.04 1 | sed -e 's/^/gray(/' -e 's/$/)/' | pastel format hex
  • xargs, xargs -L1
  • head, tail
  • sed
  • sort

Other points:

  • Warning about supported terminals (truecolor & unicode)

Literature:

pastel paint -n black --on red --bold "   ERROR!   "
echo " A serious error"

pastel paint -n black --on yellow --bold "  WARNING!  "
echo " A warning message"

pastel paint -n black --on limegreen --bold "    INFO    "
echo -n " Informational message with a "
echo -n "highlighted" | pastel paint -n default --underline
echo " word"

Support all CSS color formats

See https://developer.mozilla.org/en-US/docs/Web/CSS/color_value for all details and test cases

  • hexadecimal RRGGBB (#ff0000)
  • hexadecimal RGB (#f00)
  • rgb(0, 0, 255)
  • rgb(0%, 50%, 100%)
  • hsl(120, 100%, 75%)
  • hsl(…,…,…) in all variations
    • With and without ° sign
    • Negative angles
  • predefined color names
  • CSS Level 4 predefined names (rebeccapurple)

optional:

  • CSS Color Level 4: space-separated rgb(R G B[ A]) - only a draft
  • gray(0.3)
  • gray(30%)
  • rad instead of degrees
  • turns instead of degrees

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.