Skip to content

Commit f596cf1

Browse files
committed
Use get_until in IEx.Server
This change is necessary for forward compatibility with Erlang/OTP 26+.
1 parent 12927b8 commit f596cf1

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/iex/lib/iex/server.ex

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,29 @@ defmodule IEx.Server do
374374

375375
defp io_get(pid, prompt_type, prefix, counter) do
376376
prompt = prompt(prompt_type, prefix, counter)
377-
send(pid, {:input, self(), IO.gets(:stdio, prompt)})
377+
send(pid, {:input, self(), io_get(prompt)})
378378
end
379379

380+
defp io_get(prompt) do
381+
pid = Process.group_leader()
382+
ref = Process.monitor(pid)
383+
command = {:get_until, :unicode, prompt, __MODULE__, :__io_get__, []}
384+
send(pid, {:io_request, self(), ref, command})
385+
386+
receive do
387+
{:io_reply, ^ref, reply} ->
388+
Process.demonitor(ref, [:flush])
389+
reply
390+
391+
{:DOWN, ^ref, _, _, _} ->
392+
{:error, :terminated}
393+
end
394+
end
395+
396+
@doc false
397+
def __io_get__([], :eof), do: {:done, :eof, []}
398+
def __io_get__([], chars), do: {:done, List.to_string(chars), []}
399+
380400
defp prompt(prompt_type, prefix, counter) do
381401
{mode, prefix} =
382402
if Node.alive?() do

0 commit comments

Comments
 (0)