Open raphael-proust opened 7 years ago
That seems fine to me
at least I like the default, we are in 2017 ...
Also it would be swell if jbuilder could call ocamlc/opt with the proper -color
on more recent versions. I tried with flags
but then it's not dependent on OCaml's version.
One kink is that the run
action doesn't seem to preserve colored output for programs it runs. For example, I'm using the Alcotest library for tests which provides nicely colored output for errors, but the colors are discarded if I run the testing binary via jbuilder runtest
.
It's because processes run by jbuilder don't have direct access to the terminal. You can do:
$ jbuilder <blah> --no-buffer -j 1
to give them direct access to the terminal. When the output is redirected, AFAIK there is no standard mechanism to ask the process to print with colors
@diml that seems to have worked. Thanks!
@rgrinberg, @jeremiedimino , could anyone please add some pointer on this issue. Thank you.
Probably the easiest way to address this is using a global variable in Ansi_color
. We just need a way to set term_supports_color
if --color
is passed. This doesn't seem so clean, so let's see if @jeremiedimino has another idea.
A global variable seems fine to me in this case. I would not name it term_supports_color
though, as whether the terminal supports color or not is a fact that is independent of arguments passed on the command line. I'd name it "colors_enabled" or something similar.
@rgrinberg, @jeremiedimino : Am sorry if am failing to figure out a simple, but allow me add my intuition here.
Well, so as to know the color
of the output of the program dune is running, we need to extract it from some file foo
, pattern match on it against dune specific colors, then we tag the matched color in dune output.
So if my intuition here is correct, then I think I need more info on how to access file foo
.
Let me first clarify how dune handles colors today:
To enable/disable colors in the programs that dune launches (opam, ocaml), dune uses environment variables. See Colors.setup_env_for_colors
.
To write color output, dune creates User_message.t
values with appropriate styling that are eventually transformed to ansi escape sequences. This conversion is done in Colors.setup_err_formatter_colors
Both of thse code paths fucntion if dune detects that the terminal supports colors. We'd like to create an additional condition for this support to be enabled: whether the user requested colors or not.
Currently, jbuilder seems to always output things in colour.
Many commands have a
--color
option which takes valuesalways
/yes
,auto
,never
/no
.Could jbuilder have this option as well?