@@ -134,10 +134,45 @@ defmodule IO.ANSI do
134
134
raise ArgumentError , "invalid ANSI sequence specification: #{ other } "
135
135
end
136
136
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
+ """
137
156
def format ( chardata , emit \\ terminal? ) do
138
157
do_format ( chardata , [ ] , emit , :maybe )
139
158
end
140
159
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
+ """
141
176
def format_fragment ( chardata , emit \\ terminal? ) do
142
177
do_format ( chardata , [ ] , emit , false )
143
178
end
0 commit comments