Skip to content

Commit 1d655fa

Browse files
author
José Valim
committed
Check for terminal support from Elixir command line
1 parent 4bec785 commit 1d655fa

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

bin/elixir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ SCRIPT_PATH=$(dirname "$SELF")
8484
if [ "$OSTYPE" = "cygwin" ]; then SCRIPT_PATH=$(cygpath -m $SCRIPT_PATH); fi
8585
if [ "$MODE" != "iex" ]; then ERL="-noshell -s elixir start_cli $ERL"; fi
8686

87+
# Check for terminal support
88+
test -t 1
89+
if [ $? = 0 ]; then ERL="-elixir ansi_enabled true $ERL"; fi
90+
8791
if [ -z "$ERL_PATH" ]; then
8892
if [ -f "$SCRIPT_PATH/../releases/RELEASES" ] && [ -f "$SCRIPT_PATH/erl" ]; then
8993
ERL_PATH="$SCRIPT_PATH"/erl

lib/elixir/lib/io/ansi.ex

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ defmodule IO.ANSI do
3131
@doc """
3232
Checks if ANSI coloring is supported and enabled on this machine.
3333
34-
By default, ANSI is only enabled on UNIX machines. Enabling or
35-
disabling ANSI escapes can be done by configuring the
36-
`:ansi_enabled` value in the `:elixir` application.
34+
This function simply reads the configuration value for
35+
`:ansi_enabled` in the `:elixir` application. The value is by
36+
default false unless Elixir can detect during startup that
37+
`stdout` is a terminal.
3738
"""
3839
@spec enabled? :: boolean
3940
def enabled? do
40-
case Application.fetch_env(:elixir, :ansi_enabled) do
41-
{:ok, boolean} when is_boolean(boolean) -> boolean
42-
:error -> not match?({:win32, _}, :os.type())
43-
end
41+
Application.get_env(:elixir, :ansi_enabled, false)
4442
end
4543

4644
@doc "Resets all attributes"

lib/mix/test/mix/cli_test.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ defmodule Mix.CLITest do
147147

148148
defp mix(args) when is_list(args) do
149149
System.cmd(elixir_executable,
150-
["-e", "Application.put_env(:elixir, :ansi_enabled, false)",
151-
"-r", mix_executable, "--"|args],
150+
["-r", mix_executable, "--"|args],
152151
[stderr_to_stdout: true]) |> elem(0)
153152
end
154153

src/elixir.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
{registered, [elixir_code_server]},
88
{applications, [kernel,stdlib,crypto,compiler,syntax_tools]},
99
{mod, {elixir,[]}},
10-
{env, [{uri, #{}}]}
10+
{env, [{uri, #{}},{ansi_enabled, false}]}
1111
]}.

0 commit comments

Comments
 (0)