Skip to content

Commit 786f3ce

Browse files
committed
Add --color for easy enabling and disabling of coloring (#14183)
1 parent 98aeee3 commit 786f3ce

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

Diff for: bin/elixir

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Usage: $(basename "$0") [options] [.exs file] [data]
1818
-pz "PATH" Appends the given path to Erlang code path (*)
1919
-v, --version Prints Erlang/OTP and Elixir versions (standalone)
2020
21+
--color BOOL Enables or disables ANSI coloring
2122
--erl "SWITCHES" Switches to be passed down to Erlang (*)
2223
--eval "COMMAND" Evaluates the given command, same as -e (*)
2324
--logger-otp-reports BOOL Enables or disables OTP reporting
@@ -114,7 +115,7 @@ while [ $I -le $LENGTH ]; do
114115
-v|--no-halt)
115116
C=1
116117
;;
117-
-e|-r|-pr|-pa|-pz|--eval|--remsh|--dot-iex|--dbg)
118+
-e|-r|-pr|-pa|-pz|--eval|--remsh|--dot-iex|--dbg|--color)
118119
C=2
119120
;;
120121
--rpc-eval)

Diff for: bin/elixir.bat

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ echo -pa "PATH" Prepends the given path to Erlang code path
2424
echo -pz "PATH" Appends the given path to Erlang code path (*)
2525
echo -v, --version Prints Erlang/OTP and Elixir versions (standalone)
2626
echo.
27+
echo --color BOOL Enables or disables ANSI coloring
2728
echo --erl "SWITCHES" Switches to be passed down to Erlang (*)
2829
echo --eval "COMMAND" Evaluates the given command, same as -e (*)
2930
echo --logger-otp-reports BOOL Enables or disables OTP reporting
@@ -110,6 +111,7 @@ if ""==!par:--no-halt=! (goto startloop)
110111
if ""==!par:--remsh=! (shift && goto startloop)
111112
if ""==!par:--dot-iex=! (shift && goto startloop)
112113
if ""==!par:--dbg=! (shift && goto startloop)
114+
if ""==!par:--color=! (shift && goto startloop)
113115
rem ******* ERLANG PARAMETERS **********************
114116
if ""==!par:--boot=! (set "parsErlang=!parsErlang! -boot "%~1"" && shift && goto startloop)
115117
if ""==!par:--boot-var=! (set "parsErlang=!parsErlang! -boot_var "%~1" "%~2"" && shift && shift && goto startloop)

Diff for: bin/elixir.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Usage: $scriptName [options] [.exs file] [data]
2626
-pz "PATH" Appends the given path to Erlang code path (*)
2727
-v, --version Prints Erlang/OTP and Elixir versions (standalone)
2828
29+
--color Enables or disables ANSI coloring
2930
--erl "SWITCHES" Switches to be passed down to Erlang (*)
3031
--eval "COMMAND" Evaluates the given command, same as -e (*)
3132
--logger-otp-reports BOOL Enables or disables OTP reporting
@@ -106,7 +107,7 @@ $runErlLog = $null
106107
$private:arg = $allArgs[$i]
107108

108109
switch -exact ($arg) {
109-
{ $_ -in @("-e", "-r", "-pr", "-pa", "-pz", "--eval", "--remsh", "--dot-iex", "--dbg") } {
110+
{ $_ -in @("-e", "-r", "-pr", "-pa", "-pz", "--eval", "--remsh", "--dot-iex", "--dbg", "--color") } {
110111
++$i
111112
break
112113
}

Diff for: lib/elixir/lib/kernel/cli.ex

+18
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,24 @@ defmodule Kernel.CLI do
295295
parse_argv(t, %{config | commands: [{:parallel_require, h} | config.commands]})
296296
end
297297

298+
defp parse_argv([~c"--color", value | t], config) do
299+
config =
300+
case value do
301+
~c"true" ->
302+
Application.put_env(:elixir, :ansi_enabled, true)
303+
config
304+
305+
~c"false" ->
306+
Application.put_env(:elixir, :ansi_enabled, false)
307+
config
308+
309+
_ ->
310+
%{config | errors: ["--color : must be a boolean" | config.errors]}
311+
end
312+
313+
parse_argv(t, config)
314+
end
315+
298316
## Compiler
299317

300318
defp parse_argv([~c"-o", h | t], %{mode: :elixirc} = config) do

0 commit comments

Comments
 (0)