Output of `Mix.shell.cmd` doesn't return any colors

I’ve got a mix alias like this:
"test.watch": [fn _ -> Mix.shell().cmd("watchexec -e ex,exs,heex 'mix test --stale'") end],

it works fine, but doesn’t show any colors. Can this be fixed?

1 Like

Have you tried using the --color flag for mix test? IIRC we try to be smart about it and we don’t use colors if we’re not sure that they’d display nicely, but sometimes we get it wront, and --color should Mix to use colors if I remember it right.


Yeah, it’s the --color flag.

A bit unrelated to your question, but I use this custom mix task at work in a big shared repo. This way, I can add it to my global gitignore and nobody else has to know anything about it.

defmodule Mix.Tasks.Test.Watch do
  use Mix.Task

  @preferred_cli_env :test

  def run(args) do
    Mix.shell().cmd("echo 'Mix Test Watch v1.3'")

    Mix.shell().cmd("fswatch  --latency=0.01 --one-per-batch apps/*/lib apps/*/test |
      (mix test --color #{Enum.join(args, " ")} --listen-on-stdin)")