-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Should not send color to a pipe by default #512
Comments
Thanks for filing this. Yeah I agree, and this should be an easy detection on whether not something is a terminal. I'm undecided if this should be something I think the best way to accomplish this would be a setting of some sort, perhaps default to Thoughts? This should be an easy addition if that option works for you. |
I don't think it makes sense to have a command-line option to change this or similar; all of clap's color (or output in general) happens when emitting usage, help, or errors, which happen as part of command-line option processing. A program might want to have an auto/always/never configuration for color, and if it does (perhaps via config file read before the command line) then clap might want to provide a way to feed that in. But I'm suggesting that clap should handle this by default, and default to "auto". I think it would make sense to detect whether the target terminal (stdout/stderr) is a TTY, and only emit terminal escape sequences if so. Rust has code to implement this; see https://github.com/rust-lang/rust/blob/master/src/libtest/lib.rs#L809 and https://github.com/rust-lang/rust/blob/master/src/libsyntax/errors/emitter.rs#L476 . This likely needs to move into a library function somewhere; see rust-lang/rust#33736 . Once that library function exists, I'd suggest using it in clap to detect whether stderr goes to a terminal, and only producing escape sequences if so. Entirely optionally, you could also provide a clap option (for instance, on App) to override this detection and always/never use color. |
Sounds good. Since this is for colored output which already isn't implemented on Windows systems I'm not too worried about using Should have this implemented shortly. 👍 |
Just an update; I've been on vacation and should have this completed in a few days once I'm home. |
#520 implements this |
Clap prints color unconditionally, even when sending output somewhere other than a terminal. Redirecting output to a file, or to a pager that doesn't understand terminal escape sequences like
less -R
does, produces undesirable terminal escape sequences in the file or pager.Clap should detect when output goes somewhere other than a terminal, and suppress terminal escape sequences otherwise.
The text was updated successfully, but these errors were encountered: