Elixir: Colors in terminal lost when using mix cmd...

Created on 20 Dec 2019  ·  4Comments  ·  Source: elixir-lang/elixir

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
    Erlang/OTP 22 [erts-10.5.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] [dtrace]
    Elixir 1.9.2 (compiled with Erlang/OTP 22)
  • Operating system: OSX 10.13.6

Current behavior

I typically use mix cmd --app <app_name> mix test to run tests for individual OTP apps within an umbrella project, which totally works and is awesome. The only thing is all terminal colors are lost!

Like for example if I use the Logger module: typically depending on the log-item type (debug/error/info/warn) the terminal output color changes, which I find to be extremely useful in general. If I run mix test that goes fine and all the colors are properly displayed, but when executed with mix cmd the terminal displays the same output but without colors.

Expected behavior

Color terminal output with mix cmd! ✨

Most helpful comment

Correct. We detect if we are in a terminal and we disable ANSI escapes when you are not (such as in “mix cmd”). Depending on the command you can enable it via config (such as test) but generally you can do this too:

elixir —erl “-elixir ansi_enabled true” -S mix ...

All 4 comments

This does not address your issue, but fyi since 1.9 (or earlier), you can do:

mix test apps/<app_name>/test

from umbrella root.

@wojtekmach awesome! Totally worked 👍

Top-level mix env may not give what you want - especially if you have alias on top-level. (e.g. apps/db has test alias for resetting the database)

You can invoke the command from the child app by calling in that directory, like this:

pushd apps/app_path && mix test || popd

But still, it would be nice if mix cmd keeps the color! :rainbow:

Correct. We detect if we are in a terminal and we disable ANSI escapes when you are not (such as in “mix cmd”). Depending on the command you can enable it via config (such as test) but generally you can do this too:

elixir —erl “-elixir ansi_enabled true” -S mix ...
Was this page helpful?
0 / 5 - 0 ratings