Skip to content

Commit 2403d0c

Browse files
author
Yuki Ito
committed
IEx.Server break out of the loop when accepting :eof as input
1 parent 97ea102 commit 2403d0c

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Diff for: lib/ex_unit/lib/ex_unit/capture_io.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ defmodule ExUnit.CaptureIO do
181181
io_request({ :put_chars, mod, func, args }, buf)
182182
end
183183

184-
defp io_request({ :get_chars, _enc, _propmpt, n }, buf) when n >= 0 do
184+
defp io_request({ :get_chars, _enc, _prompt, n }, buf) when n >= 0 do
185185
{ get_chars(n), buf }
186186
end
187187

Diff for: lib/iex/lib/iex/server.ex

+16-13
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@ defmodule IEx.Server do
3030
code = config.cache
3131
line = io_get(config)
3232

33-
new_config =
34-
try do
35-
eval(code, line, counter, config)
36-
rescue
37-
exception ->
38-
print_exception(exception, System.stacktrace)
39-
config.cache('')
40-
catch
41-
kind, error ->
42-
print_error(kind, error, System.stacktrace)
43-
config.cache('')
44-
end
33+
unless line == :eof do
34+
new_config =
35+
try do
36+
eval(code, line, counter, config)
37+
rescue
38+
exception ->
39+
print_exception(exception, System.stacktrace)
40+
config.cache('')
41+
catch
42+
kind, error ->
43+
print_error(kind, error, System.stacktrace)
44+
config.cache('')
45+
end
4546

46-
do_loop(new_config)
47+
do_loop(new_config)
48+
end
4749
end
4850

4951
# Instead of doing just `:elixir.eval`, we first parse the expression to see
@@ -148,6 +150,7 @@ defmodule IEx.Server do
148150
end
149151

150152
case IO.gets(:stdio, prompt) do
153+
:eof -> :eof
151154
{ :error, _ } -> ''
152155
data -> :unicode.characters_to_list(data)
153156
end

0 commit comments

Comments
 (0)