View Source Antsy (antsy v0.2.0)
Decodes ANSI escape sequences.
Summary
Functions
Extracts ANSI escape sequences from a string.
Types
@type ansidata() :: String.t() | {:unknown, String.t()} | :invalid | :home | {:cursor, [non_neg_integer()]} | {:cursor_up, [non_neg_integer()]} | {:cursor_down, [non_neg_integer()]} | {:cursor_left, [non_neg_integer()]} | {:cursor_right, [non_neg_integer()]} | :reset | :bright | :faint | :italic | :underline | :blink_slow | :blink_rapid | :inverse | :conceal | :crossed_out | :primary_font | :font_1 | :font_2 | :font_3 | :font_4 | :font_5 | :font_6 | :font_7 | :font_8 | :font_9 | :normal | :not_italic | :no_underline | :blink_off | :inverse_off | :default_color | :default_background | :framed | :encircled | :overlined | :not_framed_encircled | :not_overlined | {:color, [0..255]} | {:color_background, [0..255]} | :black | :light_black | :black_background | :light_black_background | :red | :light_red | :red_background | :light_red_background | :green | :light_green | :green_background | :light_green_background | :yellow | :light_yellow | :yellow_background | :light_yellow_background | :blue | :light_blue | :blue_background | :light_blue_background | :magenta | :light_magenta | :magenta_background | :light_magenta_background | :cyan | :light_cyan | :cyan_background | :light_cyan_background | :white | :light_white | :white_background | :light_white_background
Functions
Extracts ANSI escape sequences from a string.
A list of strings (not an iolist!) may also be decoded.
Returns a tuple containing a list of decoded data, and a string of any remaining data that could not be completely decoded. When decoding a stream of data (e.g. from TCP or stdin), the caller should keep track of the remainder and prepend it to the next chunk of data for further decoding.
Each element in the decoded data list is one of the following:
- string - plain, unescaped text
- atom - escape sequences with no parameters
- tuple - escape sequences with parameters (256 colors, cursor movement, etc.)
{:unknown, string}
- escape sequences that are not recognized (PRs welcome!):invalid
- escape sequences that are recognized but have invalid parameters
The escape sequence names largely follow the conventions established by the IO.ANSI
module, but may not be a
one-to-one match.
Example
iex> Antsy.decode("Hello, \e[1mworld!\e[0m")
{["Hello, ", :bright, "world!", :reset], ""}