Skip to content

Commit 82655b6

Browse files
committed
Code and doc formatting fixes
1 parent 088753d commit 82655b6

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

lib/elixir/lib/io/ansi.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ defmodule IO.ANSI do
178178
## Example
179179
180180
iex> IO.ANSI.escape_fragment("Hello %{red,bright,green}yes")
181-
"Hello \e[31m\e[1m\e[32myes\e[0m"
181+
"Hello \e[31m\e[1m\e[32myes"
182182
iex> IO.ANSI.escape_fragment("%{reset}bye")
183183
"\e[0mbye"
184184

lib/iex/lib/iex/introspection.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ 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+
# We use fragments here so that escape sequences in `binary` are
14+
# treated literally and don't get converted to ANSI escapes.
1315
IO.write IEx.color_fragment(:info) <> binary <> IEx.color_reset()
1416
{ _, _ } ->
1517
IO.puts IEx.color(:error, "No docs for #{inspect module} have been found")
@@ -148,6 +150,8 @@ defmodule IEx.Introspection do
148150
defp print_doc({ { fun, _ }, _line, kind, args, doc }) do
149151
args = Enum.map_join(args, ", ", print_doc_arg(&1))
150152
IO.puts IEx.color(:info, "* #{kind} #{fun}(#{args})\n")
153+
# We use fragments here so that escape sequences in `doc` are
154+
# treated literally and don't get converted to ANSI escapes.
151155
if doc, do: IO.write IEx.color_fragment(:info) <> doc <> IEx.color_reset()
152156
end
153157

lib/iex/lib/iex/options.ex

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule IEx.Options do
22
@moduledoc """
3-
Provides an interface for changing options of the running IEx session.
3+
Provides an interface for adjusting options of the running IEx session.
44
"""
55

66
@supported_options [
@@ -12,8 +12,9 @@ defmodule IEx.Options do
1212
The value is a keyword list that should have any of the following keys
1313
specified. If any of the keys is omitted, that color is not changed.
1414
15-
* enabled -- boolean value that allows to switch the colors
15+
* enabled -- boolean value that allows for switching the coloring
1616
on and off
17+
1718
* eval_result -- color for an expression's resulting value
1819
* error -- color for error messages
1920
* info -- color for various informational messages
@@ -43,15 +44,15 @@ defmodule IEx.Options do
4344
end
4445

4546
def get(name) do
46-
raise ArgumentError, message: "Unknown IEx option #{inspect name}"
47+
raise_option(name)
4748
end
4849

4950
@doc """
50-
Sets the value of the option `name` to `value`.
51+
Sets the value for the option `name` to `value`.
5152
52-
Returns option's previous value if in the case of success.
53+
Returns option's previous value in the case of success.
5354
54-
Raises if name is not a known option or if the value is invalid.
55+
Raises if `name` is not a known option or if the value is invalid.
5556
"""
5657
def set(name, value)
5758

@@ -63,7 +64,7 @@ defmodule IEx.Options do
6364
end
6465

6566
def set(:colors, _) do
66-
raise ArgumentError, message: "Expected colors to be a keyword list"
67+
raise_value
6768
end
6869

6970
def set(:inspect, opts) when is_list(opts) do
@@ -73,25 +74,26 @@ defmodule IEx.Options do
7374
end
7475

7576
def set(:inspect, _) do
76-
raise ArgumentError, message: "Expected opts to be a keyword list"
77+
raise_value
7778
end
7879

7980
def set(name, _) do
80-
raise ArgumentError, message: "Unknown IEx option #{inspect name}"
81+
raise_option(name)
8182
end
8283

8384
@doc """
84-
Returns a string with the option's description.
85+
Returns a string with the option's description. Raises if `name` is not a
86+
known option.
8587
"""
8688
def help(name) do
8789
case @supported_options[name] do
8890
kv when is_list(kv) -> kv[:doc]
89-
nil -> :bad_option
91+
nil -> raise_option(name)
9092
end
9193
end
9294

9395
@doc """
94-
Same as `help/1` but instead of returning a string, prints it to the console.
96+
Same as `help/1` but instead of returning a string, prints it.
9597
"""
9698
def print_help(name) do
9799
IO.write help(name)
@@ -103,4 +105,12 @@ defmodule IEx.Options do
103105
def list() do
104106
Enum.map @supported_options, fn {k, _} -> k end
105107
end
108+
109+
defp raise_option(name) do
110+
raise ArgumentError, message: "Unknown IEx option #{inspect name}"
111+
end
112+
113+
defp raise_value do
114+
raise ArgumentError, message: "Expected the value to be a keyword list"
115+
end
106116
end

0 commit comments

Comments
 (0)