Skip to content

Add --color for easy enabling and disabling of ANSI coloring #14183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2025
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
3 changes: 2 additions & 1 deletion bin/elixir
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Usage: $(basename "$0") [options] [.exs file] [data]
-pz "PATH" Appends the given path to Erlang code path (*)
-v, --version Prints Erlang/OTP and Elixir versions (standalone)

--color BOOL Enables or disables ANSI coloring
--erl "SWITCHES" Switches to be passed down to Erlang (*)
--eval "COMMAND" Evaluates the given command, same as -e (*)
--logger-otp-reports BOOL Enables or disables OTP reporting
Expand Down Expand Up @@ -114,7 +115,7 @@ while [ $I -le $LENGTH ]; do
-v|--no-halt)
C=1
;;
-e|-r|-pr|-pa|-pz|--eval|--remsh|--dot-iex|--dbg)
-e|-r|-pr|-pa|-pz|--eval|--remsh|--dot-iex|--dbg|--color)
C=2
;;
--rpc-eval)
Expand Down
2 changes: 2 additions & 0 deletions bin/elixir.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ echo -pa "PATH" Prepends the given path to Erlang code path
echo -pz "PATH" Appends the given path to Erlang code path (*)
echo -v, --version Prints Erlang/OTP and Elixir versions (standalone)
echo.
echo --color BOOL Enables or disables ANSI coloring
echo --erl "SWITCHES" Switches to be passed down to Erlang (*)
echo --eval "COMMAND" Evaluates the given command, same as -e (*)
echo --logger-otp-reports BOOL Enables or disables OTP reporting
Expand Down Expand Up @@ -110,6 +111,7 @@ if ""==!par:--no-halt=! (goto startloop)
if ""==!par:--remsh=! (shift && goto startloop)
if ""==!par:--dot-iex=! (shift && goto startloop)
if ""==!par:--dbg=! (shift && goto startloop)
if ""==!par:--color=! (shift && goto startloop)
rem ******* ERLANG PARAMETERS **********************
if ""==!par:--boot=! (set "parsErlang=!parsErlang! -boot "%~1"" && shift && goto startloop)
if ""==!par:--boot-var=! (set "parsErlang=!parsErlang! -boot_var "%~1" "%~2"" && shift && shift && goto startloop)
Expand Down
3 changes: 2 additions & 1 deletion bin/elixir.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Usage: $scriptName [options] [.exs file] [data]
-pz "PATH" Appends the given path to Erlang code path (*)
-v, --version Prints Erlang/OTP and Elixir versions (standalone)

--color Enables or disables ANSI coloring
--erl "SWITCHES" Switches to be passed down to Erlang (*)
--eval "COMMAND" Evaluates the given command, same as -e (*)
--logger-otp-reports BOOL Enables or disables OTP reporting
Expand Down Expand Up @@ -106,7 +107,7 @@ $runErlLog = $null
$private:arg = $allArgs[$i]

switch -exact ($arg) {
{ $_ -in @("-e", "-r", "-pr", "-pa", "-pz", "--eval", "--remsh", "--dot-iex", "--dbg") } {
{ $_ -in @("-e", "-r", "-pr", "-pa", "-pz", "--eval", "--remsh", "--dot-iex", "--dbg", "--color") } {
++$i
break
}
Expand Down
18 changes: 18 additions & 0 deletions lib/elixir/lib/kernel/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ defmodule Kernel.CLI do
parse_argv(t, %{config | commands: [{:parallel_require, h} | config.commands]})
end

defp parse_argv([~c"--color", value | t], config) do
config =
case value do
~c"true" ->
Application.put_env(:elixir, :ansi_enabled, true)
config

~c"false" ->
Application.put_env(:elixir, :ansi_enabled, false)
config

_ ->
%{config | errors: ["--color : must be a boolean" | config.errors]}
end

parse_argv(t, config)
end

## Compiler

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