Skip to content

Commit 1457728

Browse files
committed
Make shell compatible with OTP 26 (#12114)
1 parent bd63670 commit 1457728

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

lib/iex/lib/iex/broker.ex

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,29 @@ defmodule IEx.Broker do
1010
## Shell API
1111

1212
@doc """
13-
Finds the IEx server running inside `:user_drv`, on this node exclusively.
13+
Finds the IEx server.
1414
"""
1515
@spec shell :: shell()
16+
# TODO: Use shell:whereis_shell() from Erlang/OTP 26+.
1617
def shell() do
17-
# Locate top group leader when using the "new shell".
1818
if user = Process.whereis(:user) do
19-
case :group.interfaces(user) do
20-
# Old or no shell
21-
[] ->
22-
nil
23-
24-
# Get current group from user_drv
25-
[user_drv: user_drv] ->
26-
case :user_drv.interfaces(user_drv) do
27-
[] -> nil
28-
[current_group: group] -> :group.interfaces(group)[:shell]
29-
end
19+
if user_drv = get_from_dict(user, :user_drv) do
20+
if group = get_from_dict(user_drv, :current_group) do
21+
get_from_dict(group, :shell)
22+
end
3023
end
3124
end
3225
end
3326

27+
defp get_from_dict(pid, key) do
28+
with {:dictionary, dictionary} <- Process.info(pid, :dictionary),
29+
{^key, value} <- List.keyfind(dictionary, key, 0) do
30+
value
31+
else
32+
_ -> nil
33+
end
34+
end
35+
3436
@doc """
3537
Finds the evaluator and server running inside `:user_drv`, on this node exclusively.
3638
"""

lib/iex/lib/iex/cli.ex

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,28 @@ defmodule IEx.CLI do
5050
a dumb terminal version is started instead.
5151
"""
5252
def start do
53-
if tty_works?() do
54-
:user_drv.start([:"tty_sl -c -e", tty_args()])
55-
else
56-
if get_remsh(:init.get_plain_arguments()) do
57-
IO.puts(
58-
:stderr,
59-
"warning: the --remsh option will be ignored because IEx is running on limited shell"
60-
)
61-
end
53+
# TODO: We can remove the -user callback on Erlang/OTP 26+ in favor of eval
54+
cond do
55+
Code.ensure_loaded?(:prim_tty) ->
56+
:user_drv.start(%{initial_shell: tty_args()})
57+
58+
tty_works?() ->
59+
:user_drv.start([:"tty_sl -c -e", tty_args()])
60+
61+
true ->
62+
if get_remsh(:init.get_plain_arguments()) do
63+
IO.puts(
64+
:stderr,
65+
"warning: the --remsh option will be ignored because IEx is running on limited shell"
66+
)
67+
end
6268

63-
:user.start()
69+
:user.start()
6470

65-
# IEx.Broker is capable of considering all groups under user_drv but
66-
# when we use :user.start(), we need to explicitly register it instead.
67-
# If we don't register, pry doesn't work.
68-
IEx.start([register: true] ++ options(), {:elixir, :start_cli, []})
71+
# IEx.Broker is capable of considering all groups under user_drv but
72+
# when we use :user.start(), we need to explicitly register it instead.
73+
# If we don't register, pry doesn't work.
74+
IEx.start([register: true] ++ options(), {:elixir, :start_cli, []})
6975
end
7076
end
7177

0 commit comments

Comments
 (0)