11defrecord IEx.Config , binding: nil , cache: '' , counter: 1 , scope: nil , result: nil
22
33defmodule IEx do
4+ defmodule CLI do
5+ @ moduledoc false
6+
7+ @ doc """
8+ Defines the behavour to start IEx from the command line.
9+ """
10+ def start do
11+ IEx . run ( [ remsh: get_remsh ( :init . get_plain_arguments ) ] )
12+ end
13+
14+ defp get_remsh ( [ '--remsh' , h | _ ] ) , do: list_to_binary ( h )
15+ defp get_remsh ( [ _ | t ] ) , do: get_remsh ( t )
16+ defp get_remsh ( [ ] ) , do: nil
17+ end
18+
419 @ moduledoc """
520 This module implements interactive Elixir. It provides a main
621 function, `start` which will either delegate to `tty` or `simple`.
@@ -59,17 +74,6 @@ defmodule IEx do
5974 end
6075 end
6176
62- @ doc """
63- Interface to start IEx from CLI.
64- """
65- def cli do
66- run ( [ remsh: get_remsh ( :init . get_plain_arguments ) ] )
67- end
68-
69- defp get_remsh ( [ '--remsh' , h | _ ] ) , do: list_to_binary ( h )
70- defp get_remsh ( [ _ | t ] ) , do: get_remsh ( t )
71- defp get_remsh ( [ ] ) , do: nil
72-
7377 @ doc """
7478 Runs IEx checking if tty is available or not.
7579 If so, invoke tty, otherwise go with the simple iex.
@@ -78,6 +82,7 @@ defmodule IEx do
7882 if tty_works? do
7983 tty ( opts )
8084 else
85+ :user . start
8186 IO . puts "Warning: could not run smart terminal, falling back to dumb one"
8287 simple ( opts )
8388 end
@@ -88,9 +93,6 @@ defmodule IEx do
8893 # driver twice, it would be nice and appropriate if we had
8994 # to do it just once.
9095 defp tty_works? do
91- # Dettack the error logger since we are spawning a new one
92- :error_logger . tty ( false )
93-
9496 try do
9597 port = Port . open { :spawn , :"tty_sl -c -e" } , [ :eof ]
9698 Port . close ( port )
@@ -114,22 +116,9 @@ defmodule IEx do
114116 end
115117
116118 function = fn ->
117- # We are inside the new tty and in a new process,
118- # reattach it the error logger.
119- :error_logger . tty ( true )
120119 start config
121120 end
122121
123- # Dettach the error logger because we are going to unregister
124- # the user process and start a new tty which will get control
125- # over the standardio. Dettaching it here allows us to get rid
126- # of warnings. We reattach it again when we get the new tty.
127- :error_logger . tty ( false )
128-
129- # Unregister the user process, user_drv command below
130- # will register the new one.
131- unregister_user_process
132-
133122 args =
134123 if remote do
135124 { remote , :erlang , :apply , [ function , [ ] ] }
@@ -147,7 +136,8 @@ defmodule IEx do
147136 start boot_config ( opts )
148137 end
149138
150- # This is a callback invoked by Erlang shell utilities.
139+ # This is a callback invoked by Erlang shell utilities
140+ # when someone press Ctrl+G and adds 's Elixir-IEx'.
151141 @ doc false
152142 def start ( config // nil ) do
153143 preload
@@ -170,9 +160,7 @@ defmodule IEx do
170160
171161 ## Boot Helpers
172162
173- defp boot_config ( opts ) do
174- IO . puts "Interactive Elixir (#{ System . version } ) - press Ctrl+C to exit (type h() ENTER for help)"
175-
163+ def boot_config ( opts ) do
176164 scope = :elixir . scope_for_eval (
177165 file: "iex" ,
178166 delegate_locals_to: IEx.Helpers
@@ -188,10 +176,6 @@ defmodule IEx do
188176 ]
189177 end
190178
191- defp unregister_user_process do
192- if is_pid ( Process . whereis ( :user ) ) , do: Process . unregister :user
193- end
194-
195179 defp set_expand_fun do
196180 gl = Process . group_leader
197181 glnode = node gl
0 commit comments