@@ -9,20 +9,22 @@ defmodule IEx.Introspection do
9
9
{ :module , _ } ->
10
10
case module . __info__ ( :moduledoc ) do
11
11
{ _ , binary } when is_binary ( binary ) ->
12
- IO . puts IO.ANSI . escape ( "%{yellow}# #{ inspect module } \n " )
13
- IO . write IO.ANSI . escape_fragment ( "%{yellow}" ) <> binary <> IO.ANSI . escape_fragment ( "%{reset}" )
12
+ 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.
15
+ IO . write IEx . color_fragment ( :info ) <> binary <> IEx . color_reset ( )
14
16
{ _ , _ } ->
15
- IO . puts IO.ANSI . escape ( "%{red} No docs for #{ inspect module } have been found")
17
+ IO . puts IEx . color ( :error , " No docs for #{ inspect module } have been found")
16
18
_ ->
17
- IO . puts IO.ANSI . escape ( "%{red} #{ inspect module } was not compiled with docs")
19
+ IO . puts IEx . color ( :error , " #{ inspect module } was not compiled with docs")
18
20
end
19
21
{ :error , reason } ->
20
- IO . puts IO.ANSI . escape ( "%{red} Could not load module #{ inspect module } : #{ reason } ")
22
+ IO . puts IEx . color ( :error , " Could not load module #{ inspect module } : #{ reason } ")
21
23
end
22
24
end
23
25
24
26
def h ( _ ) do
25
- IO . puts IO.ANSI . escape ( "%{red} Invalid arguments for h helper")
27
+ IO . puts IEx . color ( :error , " Invalid arguments for h helper")
26
28
end
27
29
28
30
@ doc false
@@ -34,7 +36,7 @@ defmodule IEx.Introspection do
34
36
end
35
37
36
38
unless result == :ok , do:
37
- IO . puts IO.ANSI . escape ( "%{red} No docs for #{ function } have been found")
39
+ IO . puts IEx . color ( :error , " No docs for #{ function } have been found")
38
40
39
41
:ok
40
42
end
@@ -44,9 +46,9 @@ defmodule IEx.Introspection do
44
46
:ok ->
45
47
:ok
46
48
:no_docs ->
47
- IO . puts IO.ANSI . escape ( "%{red} #{ inspect module } was not compiled with docs")
49
+ IO . puts IEx . color ( :error , " #{ inspect module } was not compiled with docs")
48
50
:not_found ->
49
- IO . puts IO.ANSI . escape ( "%{red} No docs for #{ inspect module } .#{ function } have been found")
51
+ IO . puts IEx . color ( :error , " No docs for #{ inspect module } .#{ function } have been found")
50
52
end
51
53
52
54
:ok
@@ -57,7 +59,7 @@ defmodule IEx.Introspection do
57
59
end
58
60
59
61
def h ( _ , _ ) do
60
- IO . puts IO.ANSI . escape ( "%{red} Invalid arguments for h helper")
62
+ IO . puts IEx . color ( :error , " Invalid arguments for h helper")
61
63
end
62
64
63
65
defp h_mod_fun ( mod , fun ) when is_atom ( mod ) and is_atom ( fun ) do
@@ -82,7 +84,7 @@ defmodule IEx.Introspection do
82
84
end
83
85
84
86
unless result == :ok , do:
85
- IO . puts IO.ANSI . escape ( "%{red} No docs for #{ function } /#{ arity } have been found")
87
+ IO . puts IEx . color ( :error , " No docs for #{ function } /#{ arity } have been found")
86
88
87
89
:ok
88
90
end
@@ -92,16 +94,16 @@ defmodule IEx.Introspection do
92
94
:ok ->
93
95
:ok
94
96
:no_docs ->
95
- IO . puts IO.ANSI . escape ( "%{red} #{ inspect module } was not compiled with docs")
97
+ IO . puts IEx . color ( :error , " #{ inspect module } was not compiled with docs")
96
98
:not_found ->
97
- IO . puts IO.ANSI . escape ( "%{red} No docs for #{ inspect module } .#{ function } /#{ arity } have been found")
99
+ IO . puts IEx . color ( :error , " No docs for #{ inspect module } .#{ function } /#{ arity } have been found")
98
100
end
99
101
100
102
:ok
101
103
end
102
104
103
105
def h ( _ , _ , _ ) do
104
- IO . puts IO.ANSI . escape ( "%{red} Invalid arguments for h helper")
106
+ IO . puts IEx . color ( :error , " Invalid arguments for h helper")
105
107
end
106
108
107
109
defp h_mod_fun_arity ( mod , fun , arity ) when is_atom ( mod ) and is_atom ( fun ) and is_integer ( arity ) do
@@ -147,8 +149,10 @@ defmodule IEx.Introspection do
147
149
148
150
defp print_doc ( { { fun , _ } , _line , kind , args , doc } ) do
149
151
args = Enum . map_join ( args , ", " , print_doc_arg ( & 1 ) )
150
- IO . puts IO.ANSI . escape ( "%{yellow}* #{ kind } #{ fun } (#{ args } )\n " )
151
- if doc , do: IO . write IO.ANSI . escape_fragment ( "%{yellow}" ) <> doc <> IO.ANSI . escape_fragment ( "%{reset}" )
152
+ 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.
155
+ if doc , do: IO . write IEx . color_fragment ( :info ) <> doc <> IEx . color_reset ( )
152
156
end
153
157
154
158
defp print_doc_arg ( { :// , _ , [ left , right ] } ) do
@@ -164,7 +168,7 @@ defmodule IEx.Introspection do
164
168
types = lc type inlist Kernel.Typespec . beam_types ( module ) , do: print_type ( type )
165
169
166
170
if types == [ ] do
167
- IO . puts IO.ANSI . escape ( "%{red} No types for #{ inspect module } have been found")
171
+ IO . puts IEx . color ( :error , " No types for #{ inspect module } have been found")
168
172
end
169
173
170
174
:ok
@@ -179,7 +183,7 @@ defmodule IEx.Introspection do
179
183
end
180
184
181
185
if types == [ ] do
182
- IO . puts IO.ANSI . escape ( "%{red} No types for #{ inspect module } .#{ type } have been found")
186
+ IO . puts IEx . color ( :error , " No types for #{ inspect module } .#{ type } have been found")
183
187
end
184
188
185
189
:ok
@@ -192,7 +196,7 @@ defmodule IEx.Introspection do
192
196
193
197
case types do
194
198
[ ] ->
195
- IO . puts IO.ANSI . escape ( "%{red} No types for #{ inspect module } .#{ type } /#{ arity } have been found")
199
+ IO . puts IEx . color ( :error , " No types for #{ inspect module } .#{ type } /#{ arity } have been found")
196
200
[ type ] ->
197
201
print_type ( type )
198
202
end
@@ -205,7 +209,7 @@ defmodule IEx.Introspection do
205
209
specs = lc spec inlist beam_specs ( module ) , do: print_spec ( spec )
206
210
207
211
if specs == [ ] do
208
- IO . puts IO.ANSI . escape ( "%{red} No specs for #{ inspect module } have been found")
212
+ IO . puts IEx . color ( :error , " No specs for #{ inspect module } have been found")
209
213
end
210
214
211
215
:ok
@@ -220,7 +224,7 @@ defmodule IEx.Introspection do
220
224
end
221
225
222
226
if specs == [ ] do
223
- IO . puts IO.ANSI . escape ( "%{red} No specs for #{ inspect module } .#{ function } have been found")
227
+ IO . puts IEx . color ( :error , " No specs for #{ inspect module } .#{ function } have been found")
224
228
end
225
229
226
230
:ok
@@ -235,7 +239,7 @@ defmodule IEx.Introspection do
235
239
end
236
240
237
241
if specs == [ ] do
238
- IO . puts IO.ANSI . escape ( "%{red} No specs for #{ inspect module } .#{ function } have been found")
242
+ IO . puts IEx . color ( :error , " No specs for #{ inspect module } .#{ function } have been found")
239
243
end
240
244
241
245
:ok
@@ -249,14 +253,14 @@ defmodule IEx.Introspection do
249
253
250
254
defp print_type ( { kind , type } ) do
251
255
ast = Kernel.Typespec . type_to_ast ( type )
252
- IO . puts IO.ANSI . escape ( "%{yellow} @#{ kind } #{ Macro . to_binary ( ast ) } ")
256
+ IO . puts IEx . color ( :info , " @#{ kind } #{ Macro . to_binary ( ast ) } ")
253
257
true
254
258
end
255
259
256
260
defp print_spec ( { kind , { { name , _arity } , specs } } ) do
257
261
Enum . each specs , fn ( spec ) ->
258
262
binary = Macro . to_binary Kernel.Typespec . spec_to_ast ( name , spec )
259
- IO . puts IO.ANSI . escape ( "%{yellow} @#{ kind } #{ binary } ")
263
+ IO . puts IEx . color ( :info , " @#{ kind } #{ binary } ")
260
264
end
261
265
true
262
266
end
0 commit comments