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
- italic()
-
Italic: on. Not widely supported. Sometimes treated as inverse
- 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
- 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
ansidata()
ansidata() :: ansilist | ansicode | binary
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
italic()
Italic: on. Not widely supported. Sometimes treated as inverse
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
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.3.4/IO.ANSI.html