On this page
IO.ANSI
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.
Summary
Types
Functions
- black()
-
Sets foreground color to black
- black_background()
-
Sets background color to black
- blink_off()
-
Blink: off
- blink_rapid()
-
Blink: rapid. MS-DOS ANSI.SYS; 150 per minute or more; not widely supported
- blink_slow()
-
Blink: slow. Less than 150 per minute
- blue()
-
Sets foreground color to blue
- blue_background()
-
Sets background color to blue
- bright()
-
Bright (increased intensity) or bold
- clear()
-
Clears screen
- clear_line()
-
Clears line
- color(code)
-
Sets foreground color
- color(r, g, b)
-
Sets the foreground color from individual RGB values
- color_background(code)
-
Sets background color
- color_background(r, g, b)
-
Sets the background color from individual RGB values
- conceal()
-
Conceal. Not widely supported
- crossed_out()
-
Crossed-out. Characters legible, but marked for deletion. Not widely supported
- cyan()
-
Sets foreground color to cyan
- cyan_background()
-
Sets background color to cyan
- default_background()
-
Default background color
- default_color()
-
Default text color
- enabled?()
-
Checks if ANSI coloring is supported and enabled on this machine
- encircled()
-
Encircled
- faint()
-
Faint (decreased intensity). Not widely supported
- font_1()
-
Sets alternative font 1
- font_2()
-
Sets alternative font 2
- font_3()
-
Sets alternative font 3
- font_4()
-
Sets alternative font 4
- font_5()
-
Sets alternative font 5
- font_6()
-
Sets alternative font 6
- font_7()
-
Sets alternative font 7
- font_8()
-
Sets alternative font 8
- font_9()
-
Sets alternative font 9
- format(chardata, emit? \\ enabled?())
-
Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes
- format_fragment(chardata, emit? \\ enabled?())
-
Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes
- framed()
-
Framed
- green()
-
Sets foreground color to green
- green_background()
-
Sets background color to green
- home()
-
Sends cursor home
- inverse()
-
Image: negative. Swap foreground and background
- inverse_off()
-
Image: positive. Normal foreground and background
- italic()
-
Italic: on. Not widely supported. Sometimes treated as inverse
- light_black()
-
Sets foreground color to light black
- light_black_background()
-
Sets background color to light black
- light_blue()
-
Sets foreground color to light blue
- light_blue_background()
-
Sets background color to light blue
- light_cyan()
-
Sets foreground color to light cyan
- light_cyan_background()
-
Sets background color to light cyan
- light_green()
-
Sets foreground color to light green
- light_green_background()
-
Sets background color to light green
- light_magenta()
-
Sets foreground color to light magenta
- light_magenta_background()
-
Sets background color to light magenta
- light_red()
-
Sets foreground color to light red
- light_red_background()
-
Sets background color to light red
- light_white()
-
Sets foreground color to light white
- light_white_background()
-
Sets background color to light white
- light_yellow()
-
Sets foreground color to light yellow
- light_yellow_background()
-
Sets background color to light yellow
- magenta()
-
Sets foreground color to magenta
- magenta_background()
-
Sets background color to magenta
- no_underline()
-
Underline: none
- normal()
-
Normal color or intensity
- not_framed_encircled()
-
Not framed or encircled
- not_italic()
-
Not italic
- not_overlined()
-
Not overlined
- overlined()
-
Overlined
- primary_font()
-
Sets primary (default) font
- red()
-
Sets foreground color to red
- red_background()
-
Sets background color to red
- reset()
-
Resets all attributes
- reverse()
-
Image: negative. Swap foreground and background
- reverse_off()
-
Image: positive. Normal foreground and background
- underline()
-
Underline: single
- white()
-
Sets foreground color to white
- white_background()
-
Sets background color to white
- yellow()
-
Sets foreground color to yellow
- yellow_background()
-
Sets background color to yellow
Types
ansicode()
ansicode() :: atom()
ansidata()
ansidata() :: ansilist() | ansicode() | binary()
ansilist()
ansilist() ::
maybe_improper_list(
char() | ansicode() | binary() | ansilist(),
binary() | ansicode() | []
)
Functions
black()
Sets foreground color to black.
black_background()
Sets background color to black.
blink_off()
Blink: off.
blink_rapid()
Blink: rapid. MS-DOS ANSI.SYS; 150 per minute or more; not widely supported.
blink_slow()
Blink: slow. Less than 150 per minute.
blue()
Sets foreground color to blue.
blue_background()
Sets background color to blue.
bright()
Bright (increased intensity) or bold.
clear()
Clears screen.
clear_line()
Clears line.
color(code)
color(0..255) :: String.t()
Sets foreground color.
color(r, g, b)
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)
color_background(0..255) :: String.t()
Sets background color.
color_background(r, g, b)
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()
Conceal. Not widely supported.
crossed_out()
Crossed-out. Characters legible, but marked for deletion. Not widely supported.
cyan()
Sets foreground color to cyan.
cyan_background()
Sets background color to cyan.
default_background()
Default background color.
default_color()
Default text color.
enabled?()
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()
Encircled.
faint()
Faint (decreased intensity). Not widely supported.
font_1()
Sets alternative font 1.
font_2()
Sets alternative font 2.
font_3()
Sets alternative font 3.
font_4()
Sets alternative font 4.
font_5()
Sets alternative font 5.
font_6()
Sets alternative font 6.
font_7()
Sets alternative font 7.
font_8()
Sets alternative font 8.
font_9()
Sets alternative font 9.
format(chardata, emit? \\ enabled?())
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?())
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()
Framed.
green()
Sets foreground color to green.
green_background()
Sets background color to green.
home()
Sends cursor home.
inverse()
Image: negative. Swap foreground and background.
inverse_off()
Image: positive. Normal foreground and background.
italic()
Italic: on. Not widely supported. Sometimes treated as inverse.
light_black()
Sets foreground color to light black.
light_black_background()
Sets background color to light black.
light_blue()
Sets foreground color to light blue.
light_blue_background()
Sets background color to light blue.
light_cyan()
Sets foreground color to light cyan.
light_cyan_background()
Sets background color to light cyan.
light_green()
Sets foreground color to light green.
light_green_background()
Sets background color to light green.
light_magenta()
Sets foreground color to light magenta.
light_magenta_background()
Sets background color to light magenta.
light_red()
Sets foreground color to light red.
light_red_background()
Sets background color to light red.
light_white()
Sets foreground color to light white.
light_white_background()
Sets background color to light white.
light_yellow()
Sets foreground color to light yellow.
light_yellow_background()
Sets background color to light yellow.
magenta()
Sets foreground color to magenta.
magenta_background()
Sets background color to magenta.
no_underline()
Underline: none.
normal()
Normal color or intensity.
not_framed_encircled()
Not framed or encircled.
not_italic()
Not italic.
not_overlined()
Not overlined.
overlined()
Overlined.
primary_font()
Sets primary (default) font.
red()
Sets foreground color to red.
red_background()
Sets background color to red.
reset()
Resets all attributes.
reverse()
Image: negative. Swap foreground and background.
reverse_off()
Image: positive. Normal foreground and background.
underline()
Underline: single.
white()
Sets foreground color to white.
white_background()
Sets background color to white.
yellow()
Sets foreground color to yellow.
yellow_background()
Sets background color to yellow.
© 2012 Plataformatec
Licensed under the Apache License, Version 2.0.
https://hexdocs.pm/elixir/1.6.6/IO.ANSI.html