Functionality to render ANSI escape sequences (http://en.wikipedia.org/wiki/ANSI_escape_code) — characters embedded in text used to control formatting, color, and other output options on video text terminals.
IO.ANSI
Functions #
Blink: Rapid. MS-DOS ANSI.SYS; 150 per minute or more; not widely supported
Crossed-out. Characters legible, but marked for deletion. Not widely supported.
Specs
enabled? :: boolean
Checks if ANSI coloring is supported and enabled on this machine.
This function simply reads the configuration value for
:ansi_enabled
in the :elixir
application. The value is by
default false unless Elixir can detect during startup that
both stdout
and stderr
are terminals.
Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes.
The named sequences are represented by atoms.
It will also append an IO.ANSI.reset
to the chardata when a conversion is
performed. If you don't want this behaviour, use format_fragment/2
.
An optional boolean parameter can be passed to enable or disable
emitting actual ANSI codes. When false
, no ANSI codes will emitted.
By default checks if ANSI is enabled using the enabled?/0
function.
Examples
iex> IO.ANSI.format(["Hello, ", :red, :bright, "world!"], true)
[[[[[[], "Hello, "] | "\e[31m"] | "\e[1m"], "world!"] | "\e[0m"]
Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes.
The named sequences are represented by atoms.
An optional boolean parameter can be passed to enable or disable
emitting actual ANSI codes. When false
, no ANSI codes will emitted.
By default checks if ANSI is enabled using the enabled?/0
function.
Examples
iex> IO.ANSI.format_fragment([:bright, 'Word'], true)
[[[[[[] | "\e[1m"], 87], 111], 114], 100]