ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.63k stars 401 forks source link

`--color` option #145

Open raphael-proust opened 7 years ago

raphael-proust commented 7 years ago

Currently, jbuilder seems to always output things in colour.

Many commands have a --color option which takes values always/yes, auto, never/no.

Could jbuilder have this option as well?

ghost commented 7 years ago

That seems fine to me

UnixJunkie commented 7 years ago

at least I like the default, we are in 2017 ...

c-cube commented 7 years ago

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.

basus commented 7 years ago

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.

ghost commented 7 years ago

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

basus commented 7 years ago

@diml that seems to have worked. Thanks!

lubegasimon commented 4 years ago

@rgrinberg, @jeremiedimino , could anyone please add some pointer on this issue. Thank you.

rgrinberg commented 4 years ago

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.

ghost commented 4 years ago

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.

lubegasimon commented 4 years ago

@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.

rgrinberg commented 4 years ago

Let me first clarify how dune handles colors today:

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.