@@ -43,28 +43,35 @@ defmodule IEx.Server do
43
43
44
44
defp eval_loop ( config ) do
45
45
prefix = config . cache != [ ]
46
- config . input_pid <- { :do_input , prefix , config . counter }
46
+ config . input_pid <- { :do_input , self , prefix , config . counter }
47
47
wait_input ( config )
48
48
end
49
49
50
50
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
67
52
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
68
75
{ :EXIT , _pid , :normal } ->
69
76
wait_input ( config )
70
77
{ :EXIT , pid , reason } ->
@@ -186,12 +193,12 @@ defmodule IEx.Server do
186
193
187
194
## Input loop
188
195
189
- defp input_loop ( iex_pid ) do
196
+ defp input_loop ( pid ) do
190
197
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 ) }
193
200
end
194
- input_loop ( iex_pid )
201
+ input_loop ( pid )
195
202
end
196
203
197
204
defp io_get ( prefix , counter ) do
@@ -204,11 +211,7 @@ defmodule IEx.Server do
204
211
"#{ prefix || "iex" } (#{ counter } )> "
205
212
end
206
213
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 )
212
215
end
213
216
214
217
defp remote_prefix do
0 commit comments