もた日記

くだらないことを真面目にやる

Linuxメモ : Rust製の「pastel」色の操作ができるコマンドラインツール

pastel

github.com

Rust製のpastelは色の操作(表示、変換など)ができるコマンドラインツール。

f:id:wonder-wall:20200406223520p:plain


インストール

README.mdのインストール方法によるとバイナリのダウンロードやcargoでインストールできる。

$ cargo install pastel

ヘルプメッセージ。

$ pastel --help
pastel 0.7.0
A command-line tool to generate, analyze, convert and manipulate colors

USAGE:
    pastel [OPTIONS] <SUBCOMMAND>

OPTIONS:
    -m, --color-mode <mode>
            Specify the terminal color mode: 24bit, 8bit, off, *auto*

    -f, --force-color
            Alias for --mode=24bit

        --color-picker <color-picker>
            Use a specific tool to pick the colors [possible values: gpick, xcolor,
            grabc, colorpicker, chameleon, kcolorchooser]
    -h, --help
            Prints help information

    -V, --version
            Prints version information


SUBCOMMANDS:
    color         Display information about the given color
    list          Show a list of available color names
    random        Generate a list of random colors
    distinct      Generate a set of visually distinct colors
    sort-by       Sort colors by the given property
    pick          Interactively pick a color from the screen (pipette)
    format        Convert a color to the given format
    paint         Print colored text using ANSI escape sequences
    gradient      Generate an interpolating sequence of colors
    mix           Mix two colors in the given colorspace
    colorblind    Simulate a color under a certain colorblindness profile
    set           Set a color property to a specific value
    saturate      Increase color saturation by a specified amount
    desaturate    Decrease color saturation by a specified amount
    lighten       Lighten color by a specified amount
    darken        Darken color by a specified amount
    rotate        Rotate the hue channel by the specified angle
    complement    Get the complementary color (hue rotated by 180°)
    gray          Create a gray tone from a given lightness
    to-gray       Completely desaturate a color (preserving luminance)
    textcolor     Get a readable text color for the given background color
    help          Prints this message or the help of the given subcommand(s)


使い方

color

colorに続けて色情報を与えるとその色を表示できる。
色情報はいろいろな形式で指定できる。

f:id:wonder-wall:20200406212725p:plain

list

利用可能な色名はlistで確認可能。

f:id:wonder-wall:20200406212739p:plain

139色あるようだ。

$ pastel list | wc -l
139

format

formatで出力フォーマットを指定できる。

f:id:wonder-wall:20200406212838p:plain

mix

mixで2つの色を混ぜることができる。

f:id:wonder-wall:20200406212801p:plain

distinct

distinctは指定した数で色分けしたいときの色が表示できる。
なお、この例のようにパイプを使うことも可能。

f:id:wonder-wall:20200406212820p:plain

random

randomでランダムな色を作成できる。

f:id:wonder-wall:20200406213026p:plain

to-gray

to-grayでグレースケールに変換。

f:id:wonder-wall:20200406222858p:plain