IO ANSI Plus

Build Status

Functionality to render ANSI escape sequences. Clone of IO.ANSI supporting named Xterm colors.

Installation

Add the :io_ansi_plus dependency to your mix.exs file:

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

Notes

In addition to the 16 regular ANSI colors<sup>*</sup> and their background counterparts, this package also supports the 256 Xterm colors (foreground and background).

Most of these 256 colors were given names like:

You can use color number atoms for the few colors that are unnamed:

alias IO.ANSI.Plus, as: ANSI
["Hello, ", :color163, "world!"] |> ANSI.format(true) |> IO.puts()
["Hello, ", :color163_background, "world!"] |> ANSI.format(true) |> IO.puts()

Any color can have multiple names, for example :moccasin and :navajo_white.

For details, see file config/persist_colors.exs.

*

Customization

You can create new color names or modify any predefined one by changing the dependency's config/persist_colors.exs file. You would then need to run mix deps.compile io_ansi_plus [--force] to make the changes effective.

Shortcuts

The package also provides shortcuts to drop the format calls in the following expressions:

alias IO.ANSI.Plus, as: ANSI
["Hello, ", :brown, "world!"] |> ANSI.format(true) |> IO.puts()
[:aqua, "Garry, your move:", :reset, " "] |> ANSI.format(true) |> IO.gets()

The above expressions can be shortened to:

alias IO.ANSI.Plus, as: ANSI
["Hello, ", :brown, "world!"] |> ANSI.puts(true)
[:aqua, "Garry, your move:", :reset, " "] |> ANSI.gets(true)

Examples

examples