View Source ColorPalette

A library which brings additional named colors via the 256 ANSI color escape codes into Elixir (in addition to the 16 standard named IO.ANSI colors, such as :red, :blue, :cyan, :light_red, :light_blue, :light_cyan, etc.) ColorPalette purposely has zero external dependencies.

Installation

The package can be installed by adding color_palette to your list of dependencies in mix.exs:

def deps do
  [
    {:color_palette, "~> 0.1"}
  ]
end

Documentation can be found here and a full list of colors here. IMPORTANT: note that there are background functions defined for each of the colors (and these are not shown in the docs); e.g., for ColorPalette.aqua/0 there is also ColorPalette.aqua_background/0.

Some of the colors shown in the terminal

These colors can be seen in a terminal by running this script.

Colors

Usage

This hex package adds 520 additional named colors to use in Elixir terminal scripts, based on the 256 ANSI color code sequences (so some of the color names are duplicates and reference the same color).
Note that some of the color names are approximations, as the color space for the ANSI color codes is rather limited (it's 6 bit (6 x 6 x 6 = 216 colors, plus 40 additional named colors), although there are 9 duplicate hex values so really only 247 unique colors). The color names were obtained by accessing TheColorAPI, ColorHexa, and also color-name.com.

Usage is similar to IO.ANSI. So in your Elixir script module, you can either reference ColorPalette color functions directly (e.g., ColorPalette.aero_blue/0) or you can import all of the color functions for easier usage:


def MyModule do
  import ColorPalette

  def fancy_print do
    IO.puts(aero_blue() <> "This line is in aero blue!" <> reset())
    IO.puts(alien_armpit() <> "This line is in alien armpit!" <> reset())
  end
end

MyModule.fancy_print()

So add some

:alien_armpit

to your scripts! Or how about some

:true_blue

or

:macaroni_and_cheese

or

:bright_turquoise

or

:dark_candy_apple_red

or

:laser_lemon

or some

:very_light_malachite_green

See the main module page for ColorPalette to see a list of all of the colors!

Data Sources

The 256 IO ANSI color codes are readily available, and a copy of them are stored in JSON format in this file.. These colors were manually grouped by the ColorPalette author into 11 color groups in this file (loosely based on the grouping of the web extended colors from here); note that this was a subjective process. The 16 IO.ANSI color names are stored as a a JSON file here. Color names for the 256 ANSI color codes were obtained from color-name.com,
thecolorapi.com, and ColorHexa.com , and the data are stored in JSON in this data directory. Mix.install/2 Elixir scripts to download the data for these sources are found here, here, and here, respectively. Only a subset of the names (19) from name that color were used; see the notes on how this data was obtained in this README file. The named colors from Bunt were downloaded here and included into ColorPalette.

Renamed Colors

Some of the names were in use by more than one hex value (according to the data sources); to accommodate that scenario, one of the colors was renamed with the ANSI color code appended to the end of the name so that the names would point to a unique ANSI code/hex value. For example, there's ColorPalette.blue/0 which refers to hex value #0000ff and ANSI code 21. There's also ColorPalette.blue_004/0 which has a hex value of #000080 and ANSI color code 4.

Duplicate ANSI Color Codes

Of the 256 ANSI color codes, surprisingly only 247 are unique hex values (i.e., unique colors); there are nine hex codes with duplicate hex values:

HexCode 1Code 2
#000000016
#0000ff1221
#00ff001046
#00ffff1451
#8080808244
#ff00009196
#ff00ff13201
#ffff0011226
#ffffff15231