Skip to content

Commit 03e6d3a

Browse files
author
Thomaz Leite
committed
Add docs to format/2 and format_fragment/2
1 parent 89513f9 commit 03e6d3a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/elixir/lib/io/ansi.ex

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,45 @@ defmodule IO.ANSI do
134134
raise ArgumentError, "invalid ANSI sequence specification: #{other}"
135135
end
136136

137+
@doc ~S"""
138+
Formats a chardata-like argument by converting named ANSI sequences into actual
139+
ANSI codes.
140+
141+
The named sequences are represented by atoms.
142+
143+
It will also append an `IO.ANSI.reset` to the chardata when a conversion is
144+
performed. If you don't want this behaviour, use `format_fragment/2`.
145+
146+
An optional boolean parameter can be passed to enable or disable
147+
emitting actual ANSI codes. When `false`, no ANSI codes will emitted.
148+
By default, standard output will be checked if it is a terminal capable
149+
of handling these sequences (using `terminal?/1` function)
150+
151+
## Examples
152+
153+
iex> IO.ANSI.format(["Hello, ", :red, :bright, "world!"], true)
154+
["Hello, ", "\e[31m", "\e[1m", "world!", "\e[0m"]
155+
"""
137156
def format(chardata, emit \\ terminal?) do
138157
do_format(chardata, [], emit, :maybe)
139158
end
140159

160+
@doc ~S"""
161+
Formats a chardata-like argument by converting named ANSI sequences into actual
162+
ANSI codes.
163+
164+
The named sequences are represented by atoms.
165+
166+
An optional boolean parameter can be passed to enable or disable
167+
emitting actual ANSI codes. When `false`, no ANSI codes will emitted.
168+
By default, standard output will be checked if it is a terminal capable
169+
of handling these sequences (using `terminal?/1` function)
170+
171+
## Examples
172+
173+
iex> IO.ANSI.format_fragment([:bright, 'Word'], true)
174+
["\e[1m", 87, 111, 114, 100]
175+
"""
141176
def format_fragment(chardata, emit \\ terminal?) do
142177
do_format(chardata, [], emit, false)
143178
end

0 commit comments

Comments
 (0)