Skip to content

Commit b161d80

Browse files
author
José Valim
committed
IEx now respects signals sent from user_drv, closes #1566
1 parent 748b70d commit b161d80

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

lib/iex/lib/iex/server.ex

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,35 @@ defmodule IEx.Server do
4343

4444
defp eval_loop(config) do
4545
prefix = config.cache != []
46-
config.input_pid <- { :do_input, prefix, config.counter }
46+
config.input_pid <- { :do_input, self, prefix, config.counter }
4747
wait_input(config)
4848
end
4949

5050
defp wait_input(config) do
51-
receive do
52-
{ :input, line } ->
53-
unless line == :eof do
54-
new_config =
55-
try do
56-
counter = config.counter
57-
code = config.cache
58-
eval(code, line, counter, config)
59-
catch
60-
kind, error ->
61-
print_error(kind, Exception.normalize(kind, error), System.stacktrace)
62-
config.cache('')
63-
end
64-
65-
eval_loop(new_config)
66-
end
51+
pid = config.input_pid
6752

53+
receive do
54+
{ :input, ^pid, data } when is_binary(data) ->
55+
new_config =
56+
try do
57+
line = String.to_char_list!(data)
58+
counter = config.counter
59+
code = config.cache
60+
eval(code, line, counter, config)
61+
catch
62+
kind, error ->
63+
print_error(kind, Exception.normalize(kind, error), System.stacktrace)
64+
config.cache('')
65+
end
66+
67+
eval_loop(new_config)
68+
{ :input, ^pid, :eof } ->
69+
:ok
70+
{ :input, ^pid, { :error, :interrupted } } ->
71+
io_error "** (EXIT) interrupted"
72+
eval_loop(config.cache(''))
73+
{ :input, ^pid, { :error, :terminated } } ->
74+
:ok
6875
{ :EXIT, _pid, :normal } ->
6976
wait_input(config)
7077
{ :EXIT, pid, reason } ->
@@ -186,12 +193,12 @@ defmodule IEx.Server do
186193

187194
## Input loop
188195

189-
defp input_loop(iex_pid) do
196+
defp input_loop(pid) do
190197
receive do
191-
{ :do_input, prefix, counter } ->
192-
iex_pid <- { :input, io_get(prefix, counter) }
198+
{ :do_input, ^pid, prefix, counter } ->
199+
pid <- { :input, self, io_get(prefix, counter) }
193200
end
194-
input_loop(iex_pid)
201+
input_loop(pid)
195202
end
196203

197204
defp io_get(prefix, counter) do
@@ -204,11 +211,7 @@ defmodule IEx.Server do
204211
"#{prefix || "iex"}(#{counter})> "
205212
end
206213

207-
case IO.gets(:stdio, prompt) do
208-
:eof -> :eof
209-
{ :error, _ } -> ''
210-
data -> String.to_char_list!(data)
211-
end
214+
IO.gets(:stdio, prompt)
212215
end
213216

214217
defp remote_prefix do

0 commit comments

Comments
 (0)