Strip ANSI escape codes when not writing to a terminal#120
Strip ANSI escape codes when not writing to a terminal#120fredrikfoss wants to merge 1 commit intomichaelforney:masterfrom
Conversation
ANSI color escape codes are stripped from job output when standard output is redirected to a pipe or file, unless CLICOLOR_FORCE is set to a value other than "0", or TERM is set to "dumb". This matches ninja's behavior. Signed-off-by: Fredrik Foss-Indrehus <fredrik@ffoss.net>
|
I'm highly opposed to this in general but I'm also highly opposed to this in the specific implementation details. Please do NOT use dumb generic envvars like "CLICOLOR_FORCE" as this (dumb) local convention is contaminatively contagious and affects ALL applications recursively throughout the process tree. That includes The idea of "one variable to rule them all" is dumb and ninja only supports it because the variable is the pet hobby horse of the primary ninja developer. As a matter of basic safety hygiene one must never actually use this functionality, which is another way of saying: ninja does NOT support disabling stripping of color. If one actually wished to add such a feature to samurai, it must use a correctly namespaced environment variable so that people can guarantee it affects what it's supposed to affect (and nothing else). But you might as well just control this via a cli argument and not mess with environment variables at all. |
|
I hadn't heard about CLICOLOR_FORCE before reading the ninja docs either. I'm not opposed to using a flag instead; in fact I would much prefer that. Figured I'd wait until hearing if this feature is wanted or not. I don't really have any strong opinions on this, although it is quite nice being able to run samu from the terminal and get colors, but then have them stripped when called from inside my editor without having to manually sed them out or set some non-samu option first. It's what I expect when running a terminal program in general. Anyway, you described the idea as extremely bad in #20. I can image a few small cons, but not anything that extreme (assuming a way to disable/enable stripping)? But yeah I can see it being a bit dirty. |
|
@eli-schwartz I think you are being a bit extreme here, could you please be a bit more respectful? Personally, I don't use colors much in my terminal, so I'm not really aware of the history/politics of color-controlling environment variables (it seems there is also samurai itself doesn't produce any colored output; it just writes non-colored status messages and the output of other tools. My understanding is that if the tools that are actually producing colored output supported this variable, samurai wouldn't have to do anything. In your normal terminal session, you can indicate that you want colors, and something that is saving to a log can set it based on whether it wants colors in the log. I could see an argument that it should be more automatic based on whether you're connected to a terminal, but this could easily be solved by setting the variable when connected to a TTY. Ideally, outside of samurai, like a small wrapper script test -t 1 && export FORCE_COLOR=1
exec samu "$@"Basically, my view is that post-processing command output is the wrong place to fix this problem; it's an attempt to fix-up color control of other tools. Most tools probably control color output based on That said, I think your implementation of escape sequence stripping is pretty good. I'm open to putting it in a branch if people want this behavior. |
Sorry, I am a bit passionate about the fact that the author of that website also implemented it in his projects and then goes around filing mass bugs against random projects saying "it's a standard, please follow it". |
I think that is the most important part. Tools like less(1) seem to me like a better place to mess with ansi escape sequences. |
Thanks, but in that case I think I would personally just stick to using the default version. I'm assuming it's the one package managers will ship. By the way, I was pretty conservative in the implementation as it is based on ninja's. It can be hardened quite a bit more. For example, right now it ignores OSC sequences so hyperlinks won't be stripped (although I'm not sure any compilers emit those?) It shouldn't require much change, I have a working draft. |
ANSI color escape codes are stripped from job output when standard output is redirected to a pipe or file, unless CLICOLOR_FORCE is set to a value other than "0", or TERM is set to "dumb". This matches ninja's behavior.
See #20 (comment). I'll just open the pull request before I forget.