IO.ANSI View Source
Functionality to render ANSI escape sequences.
ANSI escape sequences are characters embedded in text used to control formatting, color, and other output options on video text terminals.
Link to this section Summary
Functions
Sets foreground color to black
Sets background color to black
Blink: off
Blink: rapid. MS-DOS ANSI.SYS; 150 per minute or more; not widely supported
Blink: slow. Less than 150 per minute
Sets foreground color to blue
Sets background color to blue
Bright (increased intensity) or bold
Clears screen
Clears line
Sets foreground color
Sets the foreground color from individual RGB values
Sets background color
Sets the background color from individual RGB values
Conceal. Not widely supported
Crossed-out. Characters legible, but marked for deletion. Not widely supported
Sends cursor to the absolute position specified by line
and column
Sends cursor lines
down
Sends cursor columns
to the left
Sends cursor columns
to the right
Sends cursor lines
up
Sets foreground color to cyan
Sets background color to cyan
Default background color
Default text color
Checks if ANSI coloring is supported and enabled on this machine
Encircled
Faint (decreased intensity). Not widely supported
Sets alternative font 1
Sets alternative font 2
Sets alternative font 3
Sets alternative font 4
Sets alternative font 5
Sets alternative font 6
Sets alternative font 7
Sets alternative font 8
Sets alternative font 9
Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes
Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes
Framed
Sets foreground color to green
Sets background color to green
Sends cursor home
Image: negative. Swap foreground and background
Image: positive. Normal foreground and background
Italic: on. Not widely supported. Sometimes treated as inverse
Sets foreground color to light black
Sets background color to light black
Sets foreground color to light blue
Sets background color to light blue
Sets foreground color to light cyan
Sets background color to light cyan
Sets foreground color to light green
Sets background color to light green
Sets foreground color to light magenta
Sets background color to light magenta
Sets foreground color to light red
Sets background color to light red
Sets foreground color to light white
Sets background color to light white
Sets foreground color to light yellow
Sets background color to light yellow
Sets foreground color to magenta
Sets background color to magenta
Underline: none
Normal color or intensity
Not framed or encircled
Not italic
Not overlined
Overlined
Sets primary (default) font
Sets foreground color to red
Sets background color to red
Resets all attributes
Image: negative. Swap foreground and background
Image: positive. Normal foreground and background
Underline: single
Sets foreground color to white
Sets background color to white
Sets foreground color to yellow
Sets background color to yellow
Link to this section Types
ansicode()
View Source
ansicode() :: atom()
ansicode() :: atom()
ansidata() View Source
ansilist() View Source
Link to this section Functions
black() View Source
Sets foreground color to black.
black_background() View Source
Sets background color to black.
blink_off() View Source
Blink: off.
blink_rapid() View Source
Blink: rapid. MS-DOS ANSI.SYS; 150 per minute or more; not widely supported.
blink_slow() View Source
Blink: slow. Less than 150 per minute.
blue() View Source
Sets foreground color to blue.
blue_background() View Source
Sets background color to blue.
bright() View Source
Bright (increased intensity) or bold.
clear() View Source
Clears screen.
clear_line() View Source
Clears line.
color(code)
View Source
color(0..255) :: String.t()
color(0..255) :: String.t()
Sets foreground color.
color(r, g, b)
View Source
color(0..5, 0..5, 0..5) :: String.t()
color(0..5, 0..5, 0..5) :: String.t()
Sets the foreground color from individual RGB values.
Valid values for each color are in the range 0 to 5.
color_background(code)
View Source
color_background(0..255) :: String.t()
color_background(0..255) :: String.t()
Sets background color.
color_background(r, g, b)
View Source
color_background(0..5, 0..5, 0..5) :: String.t()
color_background(0..5, 0..5, 0..5) :: String.t()
Sets the background color from individual RGB values.
Valid values for each color are in the range 0 to 5.
conceal() View Source
Conceal. Not widely supported.
crossed_out() View Source
Crossed-out. Characters legible, but marked for deletion. Not widely supported.
cursor(line, column)
View Source
cursor(non_neg_integer(), non_neg_integer()) :: String.t()
cursor(non_neg_integer(), non_neg_integer()) :: String.t()
Sends cursor to the absolute position specified by line
and column
.
Line 0
and column 0
would mean the top left corner.
cursor_down(lines \\ 1)
View Source
cursor_down(pos_integer()) :: String.t()
cursor_down(pos_integer()) :: String.t()
Sends cursor lines
down.
cursor_left(columns \\ 1)
View Source
cursor_left(pos_integer()) :: String.t()
cursor_left(pos_integer()) :: String.t()
Sends cursor columns
to the left.
cursor_right(columns \\ 1)
View Source
cursor_right(pos_integer()) :: String.t()
cursor_right(pos_integer()) :: String.t()
Sends cursor columns
to the right.
cursor_up(lines \\ 1)
View Source
cursor_up(pos_integer()) :: String.t()
cursor_up(pos_integer()) :: String.t()
Sends cursor lines
up.
cyan() View Source
Sets foreground color to cyan.
cyan_background() View Source
Sets background color to cyan.
default_background() View Source
Default background color.
default_color() View Source
Default text color.
enabled?()
View Source
enabled?() :: boolean()
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.
encircled() View Source
Encircled.
faint() View Source
Faint (decreased intensity). Not widely supported.
font_1() View Source
Sets alternative font 1.
font_2() View Source
Sets alternative font 2.
font_3() View Source
Sets alternative font 3.
font_4() View Source
Sets alternative font 4.
font_5() View Source
Sets alternative font 5.
font_6() View Source
Sets alternative font 6.
font_7() View Source
Sets alternative font 7.
font_8() View Source
Sets alternative font 8.
font_9() View Source
Sets alternative font 9.
format(chardata, emit? \\ enabled?()) View Source
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/0
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"]
format_fragment(chardata, emit? \\ enabled?()) View Source
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]
framed() View Source
Framed.
green() View Source
Sets foreground color to green.
green_background() View Source
Sets background color to green.
home() View Source
Sends cursor home.
inverse() View Source
Image: negative. Swap foreground and background.
inverse_off() View Source
Image: positive. Normal foreground and background.
italic() View Source
Italic: on. Not widely supported. Sometimes treated as inverse.
light_black() View Source
Sets foreground color to light black.
light_black_background() View Source
Sets background color to light black.
light_blue() View Source
Sets foreground color to light blue.
light_blue_background() View Source
Sets background color to light blue.
light_cyan() View Source
Sets foreground color to light cyan.
light_cyan_background() View Source
Sets background color to light cyan.
light_green() View Source
Sets foreground color to light green.
light_green_background() View Source
Sets background color to light green.
light_magenta() View Source
Sets foreground color to light magenta.
light_magenta_background() View Source
Sets background color to light magenta.
light_red() View Source
Sets foreground color to light red.
light_red_background() View Source
Sets background color to light red.
light_white() View Source
Sets foreground color to light white.
light_white_background() View Source
Sets background color to light white.
light_yellow() View Source
Sets foreground color to light yellow.
light_yellow_background() View Source
Sets background color to light yellow.
magenta() View Source
Sets foreground color to magenta.
magenta_background() View Source
Sets background color to magenta.
no_underline() View Source
Underline: none.
normal() View Source
Normal color or intensity.
not_framed_encircled() View Source
Not framed or encircled.
not_italic() View Source
Not italic.
not_overlined() View Source
Not overlined.
overlined() View Source
Overlined.
Sets primary (default) font.
Sets foreground color to red.
red_background() View Source
Sets background color to red.
reset() View Source
Resets all attributes.
reverse() View Source
Image: negative. Swap foreground and background.
reverse_off() View Source
Image: positive. Normal foreground and background.
underline() View Source
Underline: single.
white() View Source
Sets foreground color to white.
white_background() View Source
Sets background color to white.
yellow() View Source
Sets foreground color to yellow.
yellow_background() View Source
Sets background color to yellow.