Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bin/elixir
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ starts_with () {
}

ERL_EXEC="erl"
MODE="cli"
I=1
E=0
LENGTH=$#
Expand All @@ -104,9 +105,13 @@ while [ $I -le $LENGTH ]; do
S=0
C=0
case "$1" in
+elixirc|+iex)
+elixirc)
C=1
;;
+iex)
C=1
MODE="iex"
;;
-v|--no-halt|--dbg)
C=1
;;
Expand Down Expand Up @@ -223,7 +228,7 @@ fi
ERTS_BIN=
ERTS_BIN="$ERTS_BIN"

set -- "$ERTS_BIN$ERL_EXEC" -noshell -elixir_root "$SCRIPT_PATH"/../lib -pa "$SCRIPT_PATH"/../lib/elixir/ebin $ELIXIR_ERL_OPTIONS -s elixir start_cli $ERL "$@"
set -- "$ERTS_BIN$ERL_EXEC" -noshell -elixir_root "$SCRIPT_PATH"/../lib -pa "$SCRIPT_PATH"/../lib/elixir/ebin $ELIXIR_ERL_OPTIONS -s elixir start_$MODE $ERL "$@"

if [ -n "$RUN_ERL_PIPE" ]; then
ESCAPED=""
Expand Down
11 changes: 8 additions & 3 deletions bin/elixir.bat
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ rem Option which determines whether the loop is over
set endLoop=0

rem Designates which mode / Elixir component to run as
set runMode="elixir"
set runMode="cli"

rem Designates the path to the current script
set SCRIPT_PATH=%~dp0
Expand All @@ -106,7 +106,7 @@ if !endLoop! == 1 (
)
rem ******* EXECUTION OPTIONS **********************
if !par!=="--werl" (set useWerl=1 && goto startloop)
if !par!=="+iex" (set parsElixir=!parsElixir! +iex && goto startloop)
if !par!=="+iex" (set parsElixir=!parsElixir! +iex && set runMode="iex" && goto startloop)
if !par!=="+elixirc" (set parsElixir=!parsElixir! +elixirc && goto startloop)
rem ******* EVAL PARAMETERS ************************
if ""==!par:-e=! (
Expand Down Expand Up @@ -164,8 +164,13 @@ reg query HKCU\Console /v VirtualTerminalLevel 2>nul | findstr /e "0x1" >nul 2>n
if %errorlevel% == 0 (
set beforeExtra=-elixir ansi_enabled true !beforeExtra!
)
if !runMode! == "iex" (
set beforeExtra=-s elixir start_iex !beforeExtra!
) else (
set beforeExtra=-s elixir start_cli !beforeExtra!
)

set beforeExtra=-noshell -elixir_root "!SCRIPT_PATH!..\lib" -pa "!SCRIPT_PATH!..\lib\elixir\ebin" -s elixir start_cli !beforeExtra!
set beforeExtra=-noshell -elixir_root "!SCRIPT_PATH!..\lib" -pa "!SCRIPT_PATH!..\lib\elixir\ebin" !beforeExtra!

if defined ELIXIR_CLI_DRY_RUN (
if defined useWerl (
Expand Down
2 changes: 1 addition & 1 deletion bin/iex
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ readlink_f () {

SELF=$(readlink_f "$0")
SCRIPT_PATH=$(dirname "$SELF")
exec "$SCRIPT_PATH"/elixir --no-halt --erl "-user elixir" -e ":elixir.start_iex()" +iex "$@"
exec "$SCRIPT_PATH"/elixir --no-halt --erl "-user elixir" +iex "$@"
2 changes: 1 addition & 1 deletion bin/iex.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ goto end

:run
if defined IEX_WITH_WERL (set __ELIXIR_IEX_FLAGS=--werl) else (set __ELIXIR_IEX_FLAGS=)
call "%~dp0\elixir.bat" --no-halt --erl "-user elixir" -e ":elixir.start_iex()" +iex %__ELIXIR_IEX_FLAGS% %*
call "%~dp0\elixir.bat" --no-halt --erl "-user elixir" +iex %__ELIXIR_IEX_FLAGS% %*
:end
endlocal
4 changes: 3 additions & 1 deletion lib/elixir/src/elixir.erl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ start_cli() ->
'Elixir.Kernel.CLI':main(init:get_plain_arguments()),
elixir_config:booted().

%% TODO: Delete prim_tty branches and -user on Erlang/OTP 26.
%% TODO: Delete prim_tty branches and -user on Erlang/OTP 26
%% and add "-e :elixir.start_iex" to bin/iex instead of $MODE.
start() ->
case code:ensure_loaded(prim_tty) of
{module, _} ->
Expand All @@ -207,6 +208,7 @@ start() ->
start_iex() ->
case code:ensure_loaded(prim_tty) of
{module, _} ->
start_cli(),
spawn(fun() ->
elixir_config:wait_until_booted(),
(shell:whereis() =:= undefined) andalso 'Elixir.IEx':cli()
Expand Down
14 changes: 11 additions & 3 deletions lib/iex/lib/iex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ defmodule IEx do

@doc """
Returns `true` if IEx was started, `false` otherwise.

This means the IEx application was started, but not
that its CLI interface is running.
"""
@spec started?() :: boolean()
def started? do
Expand Down Expand Up @@ -857,6 +860,8 @@ defmodule IEx do

# This is a callback invoked by Erlang shell utilities
# when someone presses Ctrl+G and adds `s 'Elixir.IEx'`.
# Let's consider exposing this as iex:start() and rename
# elixir:start_iex() to iex:cli().
@doc false
def start(opts \\ [], mfa \\ {IEx, :dont_display_result, []}) do
# TODO: Keep only this branch, delete optional args and mfa,
Expand All @@ -869,10 +874,13 @@ defmodule IEx do
end)
else
spawn(fn ->
{:ok, _} = Application.ensure_all_started(:elixir)
System.wait_until_booted()
:ok = :io.setopts(binary: true, encoding: :unicode)
case :init.notify_when_started(self()) do
:started -> :ok
_ -> :init.wait_until_started()
end

{:ok, _} = Application.ensure_all_started(:iex)
:ok = :io.setopts(binary: true, encoding: :unicode)
_ = for fun <- Enum.reverse(after_spawn()), do: fun.()
IEx.Server.run_from_shell(opts, mfa)
end)
Expand Down
12 changes: 4 additions & 8 deletions lib/iex/lib/iex/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule IEx.CLI do

def deprecated do
if tty_works?() do
:user_drv.start([:"tty_sl -c -e", old_tty_args()])
:user_drv.start([:"tty_sl -c -e", tty_args()])
else
if get_remsh(:init.get_plain_arguments()) do
IO.puts(
Expand All @@ -20,14 +20,10 @@ defmodule IEx.CLI do
# IEx.Broker is capable of considering all groups under user_drv but
# when we use :user.start(), we need to explicitly register it instead.
# If we don't register, pry doesn't work.
IEx.start([register: true] ++ options())
IEx.start([register: true] ++ options(), {:elixir, :start_cli, []})
end
end

def prompt(_n) do
[]
end

# Check if tty works. If it does not, we fall back to the
# simple/dumb terminal. This is starting the linked in
# driver twice, it would be nice and appropriate if we had
Expand All @@ -41,7 +37,7 @@ defmodule IEx.CLI do
end
end

defp old_tty_args do
defp tty_args do
if remote = get_remsh(:init.get_plain_arguments()) do
remote = List.to_atom(append_hostname(remote))

Expand Down Expand Up @@ -77,7 +73,7 @@ defmodule IEx.CLI do
end

defp local_start_mfa do
{IEx, :start, [options()]}
{IEx, :start, [options(), {:elixir, :start_cli, []}]}
end

def remote_start(parent, ref) do
Expand Down