Skip to content

Commit 088753d

Browse files
committed
Provide color options for escape_fragments
1 parent 7632c0b commit 088753d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/iex/lib/iex.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,20 @@ defmodule IEx do
246246
colors = IEx.Options.get(:colors)
247247
IO.ANSI.escape "%{#{colors[color_name]}}#{string}", colors[:enabled]
248248
end
249+
250+
@doc """
251+
Returns an escaped fragment using the specified color.
252+
"""
253+
def color_fragment(color_name) do
254+
colors = IEx.Options.get(:colors)
255+
IO.ANSI.escape_fragment "%{#{colors[color_name]}}", colors[:enabled]
256+
end
257+
258+
@doc """
259+
Returns an escaped fragment that resets colors and attributes.
260+
"""
261+
def color_reset() do
262+
colors = IEx.Options.get(:colors)
263+
IO.ANSI.escape_fragment "%{reset}", colors[:enabled]
264+
end
249265
end

lib/iex/lib/iex/introspection.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule IEx.Introspection do
1010
case module.__info__(:moduledoc) do
1111
{ _, binary } when is_binary(binary) ->
1212
IO.puts IEx.color(:info, "# #{inspect module}\n")
13-
IO.write IO.ANSI.escape_fragment("%{yellow}") <> binary <> IO.ANSI.escape_fragment("%{reset}")
13+
IO.write IEx.color_fragment(:info) <> binary <> IEx.color_reset()
1414
{ _, _ } ->
1515
IO.puts IEx.color(:error, "No docs for #{inspect module} have been found")
1616
_ ->
@@ -148,7 +148,7 @@ defmodule IEx.Introspection do
148148
defp print_doc({ { fun, _ }, _line, kind, args, doc }) do
149149
args = Enum.map_join(args, ", ", print_doc_arg(&1))
150150
IO.puts IEx.color(:info, "* #{kind} #{fun}(#{args})\n")
151-
if doc, do: IO.write IO.ANSI.escape_fragment("%{yellow}") <> doc <> IO.ANSI.escape_fragment("%{reset}")
151+
if doc, do: IO.write IEx.color_fragment(:info) <> doc <> IEx.color_reset()
152152
end
153153

154154
defp print_doc_arg({ ://, _, [left, right] }) do

0 commit comments

Comments
 (0)