Skip to content

Commit c6817c8

Browse files
author
Thomaz Leite
committed
Remove IEx options from default args in ANSIDocs
1 parent 6fc468b commit c6817c8

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

lib/iex/lib/iex/ansi_docs.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule IEx.ANSIDocs do
66
@doc """
77
Prints the head of the documentation (i.e. the function signature)
88
"""
9-
def print_heading(string, use_ansi // IO.ANSI.terminal?, colors // IEx.Options.get(:colors)) do
9+
def print_heading(string, use_ansi // IO.ANSI.terminal?, colors // []) do
1010
if use_ansi do
1111
write_doc_heading(string, colors)
1212
else
@@ -26,7 +26,7 @@ defmodule IEx.ANSIDocs do
2626
@doc """
2727
Prints the documentation body.
2828
"""
29-
def print(doc, use_ansi // IO.ANSI.terminal?, colors // IEx.Options.get(:colors)) do
29+
def print(doc, use_ansi // IO.ANSI.terminal?, colors // []) do
3030
if use_ansi do
3131
doc
3232
|> String.split(["\r\n","\n"], trim: false)

lib/iex/lib/iex/introspection.ex

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ defmodule IEx.Introspection do
1212
if function_exported?(module, :__info__, 1) do
1313
case module.__info__(:moduledoc) do
1414
{ _, binary } when is_binary(binary) ->
15-
IEx.ANSIDocs.print_heading(inspect module)
16-
IEx.ANSIDocs.print(binary)
15+
use_ansi = IO.ANSI.terminal?
16+
colors = IEx.Options.get(:colors)
17+
IEx.ANSIDocs.print_heading(inspect(module), use_ansi, colors)
18+
IEx.ANSIDocs.print(binary, use_ansi, colors)
1719
{ _, _ } ->
1820
nodocs(inspect module)
1921
_ ->
@@ -158,8 +160,10 @@ defmodule IEx.Introspection do
158160

159161
defp print_doc({ { fun, _ }, _line, kind, args, doc }) do
160162
args = Enum.map_join(args, ", ", &print_doc_arg(&1))
161-
IEx.ANSIDocs.print_heading("#{kind} #{fun}(#{args})")
162-
if doc, do: IEx.ANSIDocs.print(doc)
163+
use_ansi = IO.ANSI.terminal?
164+
colors = IEx.Options.get(:colors)
165+
IEx.ANSIDocs.print_heading("#{kind} #{fun}(#{args})", use_ansi, colors)
166+
if doc, do: IEx.ANSIDocs.print(doc, use_ansi, colors)
163167
end
164168

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

lib/iex/test/iex/ansi_docs_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule IEx.AnsiDocsTest do
1414
@opts [colors: @colors]
1515

1616
def format(str, use_ansi // true) do
17-
cmd = "IEx.ANSIDocs.print(#{inspect str}, #{inspect use_ansi})"
17+
cmd = "IEx.ANSIDocs.print(#{inspect str}, #{inspect use_ansi}, #{inspect @colors})"
1818
capture_iex(cmd, @opts)
1919
end
2020

@@ -23,7 +23,7 @@ defmodule IEx.AnsiDocsTest do
2323
end
2424

2525
test "ansi heading is formatted" do
26-
result = capture_iex("IEx.ANSIDocs.print_heading(\"wibble\", true)", @opts)
26+
result = capture_iex("IEx.ANSIDocs.print_heading(\"wibble\", true, #{inspect @colors})", @opts)
2727
assert String.starts_with?(result, "\e[0m\n\e[7m\e[33m\e[1m")
2828
assert String.ends_with?(result, "\e[0m\n\e[0m")
2929
assert String.contains?(result, " wibble ")

0 commit comments

Comments
 (0)