View Source ExAequo.Color (ExAequo v0.5.2)

## Support for the 256 ANSI and full RGB colors

N.B. Does, of course, respect the usage of the $NO_COLOR variable

The most basic approach is to use the generated escape sequences directly in your code, e.g.

    IO.puts(ExAequo.Color.rgb(250, 148, 13) <> "Brownish Orange" <> ExAequo.Color.reset)

rgb

rgb

The generated escape codes would be:

iex(1)> rgb(250, 148, 13)
"\e[38;2;250;148;13m"

iex(2)> reset()
"\e[0m"

format

format

But like IO.ANSI a convenience function called format is available

iex(3)> format(["Hello", "World"])
["Hello", "World"]

As one can see it is tailor made for IO.puts and may be converted into a string by means of IO.chardata_to_string, this conversion can also be done by format itself

iex(4)> format(["Hello", "World"], to_string: true)
"HelloWorld"

putc

putc

A shortcut for

      color_definition_list
      |> format
      |> IO.puts

RGB

In order to get colors into the mix we can use, atoms (for named colors or instructions like reset) or triples for RGB colors

iex(5)> format([{100, 20, 150}, "Deep Purple (pun intended)", :reset])
["\e[38;2;100;20;150m", "Deep Purple (pun intended)", "\e[0m"]

8 Color Space

And here are some nice names, which shall work on all terminals

iex(6)> format([:red, "red", :blue, "blue"])
["\e[31m", "red", "\e[34m", "blue"]

Oftentimes you will pass a variable to format and not a literal array, then the usage of the reset: true option might come in handy

iex(7)> some_values = [:azure1, "The sky?"]
...(7)> format(some_values, reset: true, to_string: true)
"\e[38;2;240;255;255mThe sky?\e[0m"

256 Colors

iex(8)> format([:color242, :color142, :color42])
["\e[38;5;242m", "\e[38;5;142m", "\e[38;5;42m"]

escript-ls_colors

Escript ls_colors

Test some colors

    ls_colors :red Red :reset 100,20,150 Deep Purple

Show some colors

    ls_colors -l|--list red_range green_range blue_range

Link to this section Summary

Link to this section Functions