-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
Disable terminal ANSI escape sequences when the output is a file #498
Comments
I'm not very familiar with rubocop's source code, but I checked it out and it seemed like a good solution to decorate the output used in the base formatter and then check whether it is a tty in order to add ansi escape sequences. |
@fuadsaud Feel free to send a PR implementing your proposed solution :-) This won't affect paging programs understanding ANSI colors like |
Yes, a simple check for IO#tty? will return false for pipes and such. I'm not sure how to handle this either. I'm not sure when I'll have time, but I plan to look into it. If anyone has a better idea, please go on. |
I think the problem should be solved in the Rainbow gem. I have opened an issue over there. |
Issue 16 in sickill/rainbow has been closed and version 1.99.0 of that gem has the fix. I have tested manually that color codes are not included when stderr is redirected to a file. A |
Copy pasting what I just wrote in #497 : I have just released a new rainbow 1.99 which has this fixed (checks if any of stdout and stderr is not a tty). rainbow will drop monkey patching of String class in 2.0 and this 1.99 release is a preparation for that. You can now upgrade to 1.99 and convert all "foo".color(:red) to Rainbow("foo").color(:red). When 2.0 is out you'll be prepared. |
I don't think this issue is solved. The |
@yujinakayama rubocop can disable rainbow (via A solution for that would be something like this: FileRainbow = Rainbow.get_instance
FileRainbow.enabled = <...your custom condition...> For example: # this adds color if the terminal is a TTY
Rainbow("foo").color(:red) # => "\e[31mfoo\e[0m"
# this never adds a color
FileRainbow.enabled = false
FileRainbow("foo").color(:red) # => "foo" Would that solve this rubocop problem? |
Basically, each formatter could acquire its own instance of Rainbow and rubocop could disable coloring on the Rainbow instances that are used by formatters that output to files. |
Yes. The proposed solution is great. If |
👍 on I should find some time for this in the coming days, I'll let you know when it gets implemented. |
@sickill Thanks! |
@yujinakayama it's there. I have just released 1.99.1 with a support for multiple rainbow wrapper instances. Check the readme section "Advanced usage". |
@sickill Thanks! I'll try later. |
The continuation of #497.
The text was updated successfully, but these errors were encountered: