Disable color when output to file using --out
/ allow --color
to be a per-formatter option like --out
#1288
Labels
good first issue
Good for newcomers
🙏 help wanted
Help wanted - not prioritized by core team
✅ accepted
The core team has agreed that it is a good idea to fix this
⚡ enhancement
Request for new functionality
Summary
It seems like the default behavior should be for formatters that are output to the screen to have color enabled by default, and formatters that are directed to files to have no color by default, so that you can open them in an editor and not see gobbledeygook.
The default should be overridable, however, in case you really did want to view the saved output on a terminal later (perhaps with
less -R
).Current Behavior
lib/cucumber/formatter/ansicolor.rb
only disables color if you redirect stdout, as incucumber > file
:However, it doesn't provide any way to disable color for when directing a specific formatter to a
file with:
Expected Behavior
1. Default behavior
Formatters that are output to the screen (
@io.tty?
) should have color enabled by defaultFormatters that are directed to files (
@io.is_a?(File)
) to have no color by default.The help says it is based on the output destination but that is not true when using
--out
.2. Ability to enable/disable color on a per-formatter basis (like
--out
)It would be nice if you could disable color on a per-formatter basis, like how you can direct to a
different output on a per-formatter basis.
Maybe something like this:
but since --color/--no-color is a global state, the last flag changes it for all formatters.
So the best you can do with --no-color is turn off color for all formatters, including the one
being output to a tty STDOUT.
Possible Solution
One solution/workaround would be to strip out color in
format_string
:That seems to work for me, striping out all color except the summary at the bottom. Probably not the best solution, though.
Probably should move
Cucumber::Term::ANSIColor.coloring?
so that it's an instance method instead of a class method...Steps to Reproduce (for bugs)
cucumber --format pretty --out pretty.txt --format progress features/
pretty.txt
contains unwanted color codes.Your Environment
cucumber-3.1.0
cucumber-rails-1.5.0
The text was updated successfully, but these errors were encountered: