-
-
Notifications
You must be signed in to change notification settings - Fork 134
Description
There are plenty of cases where a process's output isn't directly connected to a TTY, but will still be eventually sent to a TTY. For example, running a test in either ninja or bazel will buffer the output so that things can run in parallel, but still have clean contiguous output for each one rather than a jumbled mess of interleaved output from different processes. This is why tools support flags like --color=always or --force_color. There is also the semi-standard FORCE_COLOR environment variable (and it's mate NO_COLOR.)
I think the right thing for a library to do is for the automatic detection logic to honor FORCE_COLOR/NO_COLOR, but also provide a way for the application to indicate that it really does or does not want color, overriding the library's detection mechanism entirely. This is important both to support application-level flags like --force-color, as well as cases where the application streams into an ostringstream buffer that it intends to later write to stdout. For example, it may want to buffer up a large block of related output then write that to the real stdout under a lock, for the same reason as ninja and bazel, but to prevent interleaving of threads rather than processes.