-
Notifications
You must be signed in to change notification settings - Fork 80
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
Colors for ocaml >= 4.03 #87
Comments
Storing color escape codes in the log should be fine as long as users use color-aware tools to read the log (eg. I think a decent solution is to keep expecting users to write |
Sure, I'll try and make a PR as soon as possible |
Seems like there is already support for it using the |
I don't think this is enough, |
Please really don't use
@gasche What do you mean by this ? Where should this be handled then ? |
I find it weird that build system's implementation would need to be modified because a compiler suddenly gained the ability to use colors on certain cases. The compiler is trying to guess whether colors should be used in a particular case, and the current heuristics fail to activate colors for the build-system use-case, which is to run the compiler in non-interactive mode. Is it the build-system job to explicitly point out that, while not calling the compiler interactively, it still wants colors? But then how many other tools would have to be modified in the same way? Or should the compiler heuristics be changed to use colors in this family of use-cases? But then how should they be distinguished from the cases where we do not want color? (Do we always want colors?). My gut feeling in this case is that we should delegate the decision to the user: give them a way to communicate to the compiler that they want color across the build-system invocation. This is why I suggested an environment variable. I think that would be flexible enough for what @Gbury wants (basically he can insert this in a You could alternatively argue that the build-system, when invoked interactively, does redirect the output to a file for internal logging reasons but ultimately shows the output to the user as if they had invoked the compiler directly. And that it should therefore communicate to the compiler the fact that the output is intended for interactive use. It would be nice if this was the path of least resistance: if the natural option for a build-system (or other tools) to invoke the compiler did propagate this information naturally. I would agree with modifying ocamlbuild so that if behaves in this way, but I would like the change not to be too ad-hoc or heavy-handed. for example always passing To summarize: in a perfect world, ocamlbuild and all other tools would do the right thing by default because the compiler heuristic just works. Maybe that cannot exist, and ocamlbuild and similar tools should be changed to propagate to their callees the intent to interactively show the result; but then I would like a way to do this that works as uniformly as possible across the called tools that do have a specific user-facing-output mode, instead of having to single-case each tool (here the OCaml compiler). I am not sure whether this is possible today (OCaml and Clang's heuristics are good enough for that) or whether extra compiler-side support is needed. |
Le mardi, 24 mai 2016 à 16:40, Gabriel Scherer a écrit :
Well if the build system has internal rules which are responsible to invoke the actual compilers that gained that ability, I personally don't find this weird.
This is the way any tool that produces colored output works.
If you want a good end-user experience this is what should be done in my opinion. Add an option —color={auto,always,never} to ocamlbuild itself that eventually sets a global boolean color parameter and defaults to auto along with an OCAMLBUILD_COLOR that allows to override the default. In the auto case ocamlbuild detects whether its stdout/sdterr is a tty and sets the color parameter to true if that is the case and false otherwise. This color parameter must be propagated in the build rules for the tools that support colored output control. Best, Daniel |
Thanks for the precise recommendation: it sounds reasonable and I can follow it. If you think that an |
Yes. Note, the |
Yep, the correct cascading order is "env < cli < file-local settings". |
So, I'd like to try and do a PR on the ocaml repo to add support for the |
I would let the code speak. I think the most natural place to test |
I opened ocaml/ocaml#1098 to solve this issue (hope I understood the discussion in here correctly), and hope that it will be considered for the 4.05 release (fingers crossed). |
…colors Since 4.03, OCaml supports coloring its messages to standard output and standard error, depending on the "-color" argument ({always,never,auto}). This commit adds support for the environment variable "OCAML_COLOR" (which value can as well be {always,never,auto}). The command line argument "-color" takes precedence, "OCAML_COLOR" is only taken into consideration if no "-color" is provided. The motivation for this is that the user should have control over coloring OCaml's output messages. OCamlbuild, a widely used build tool executes OCaml not under a tty (and OCaml does not colorize errors and warnings), which lead various packages use `color(always)` in their `_tags` files, which breaks with other (non-interactive) programs (i.e. editor helpers). Further discussion was done at ocaml/ocamlbuild#87 and ocaml#1098.
…colors Since 4.03, OCaml supports coloring its messages to standard output and standard error, depending on the "-color" argument ({always,never,auto}). This commit adds support for the environment variable "OCAML_COLOR" (which value can as well be {always,never,auto}). The command line argument "-color" takes precedence, "OCAML_COLOR" is only taken into consideration if no "-color" is provided. The motivation for this is that the user should have control over coloring OCaml's output messages. OCamlbuild, a widely used build tool executes OCaml not under a tty (and OCaml does not colorize errors and warnings), which lead various packages use `color(always)` in their `_tags` files, which breaks with other (non-interactive) programs (i.e. editor helpers). Further discussion was done at ocaml/ocamlbuild#87 and #1098.
…colors Since 4.03, OCaml supports coloring its messages to standard output and standard error, depending on the "-color" argument ({always,never,auto}). This commit adds support for the environment variable "OCAML_COLOR" (which value can as well be {always,never,auto}). The command line argument "-color" takes precedence, "OCAML_COLOR" is only taken into consideration if no "-color" is provided. The motivation for this is that the user should have control over coloring OCaml's output messages. OCamlbuild, a widely used build tool executes OCaml not under a tty (and OCaml does not colorize errors and warnings), which lead various packages use `color(always)` in their `_tags` files, which breaks with other (non-interactive) programs (i.e. editor helpers). Further discussion was done at ocaml/ocamlbuild#87 and ocaml#1098.
Ocaml 4.03 comes with shiny colors for error and warnings (which considerably improve readability) however, it seems the heuristics used currently by default suppresses the colored output when invoked by ocamlbuild, most likely because of the log file: colored output prints fine on the terminal, but is quite ugly in the build log.
For those who rarely directly read the log, forcing colored output from the compiler is a solution, but it doesn't really feel right.
The text was updated successfully, but these errors were encountered: