Hi.
Is it possible to get color text in less, more or other pagers while
piping the color output of Cucumber and RSpec? If it’s not possible is
there any other methods to work with the color text in a console without
permanent “rewinding†the output back to the beginning?
Thanks.
P. A. [email protected] on 2009-12-02 at 09:08:
Is it possible to get color text in less, more or other pagers while
piping the color output of Cucumber and RSpec?
Have a look at these options for less
:
-R or --RAW-CONTROL-CHARS
Like -r, but only ANSI "color" escape sequences are output in
"raw" form. Unlike -r, the screen appearance is maintained correctly
in most cases.
You can set default options for less to use via the LESS evironment
variable.
As an example, here is the value of mine:
$ echo $LESS
-X -e -R
Cheers,
Paul
I’ve known about the -R option but it doesn’t work for me.
$ cucumber #=> color output
$ cucumber | less -R #=> monochrome
$ spec -c <path/to/spec> #=> color output
$ spec -c <path/to/spec> | less -R #=> monochrome
but
$ ls --color=always | less -R #=> color output
It seems that your system has addition preferences that enables you to
pipe the color tags in output to less. Could you tell me how did you
achive it?
I solve it by myself.
To enable piping color output in Cucumber it needs to run the cucumber
command with the -c option.
$ cucumber -c | less #=> color output
To enable piping color output in RSpec it needs to set the RSPEC_COLOR
environment variable to true.
$ export RSPEC_COLOR=true
$ spec path/to/spec | less #=> color output
However, if RSPEC_COLOR is set to true the output to a file will include
color tags. To prevent it, it needs to unset RSPEC_COLOR.
$ unset RSPEC_COLOR
$ spec path/to/spec > file #=> no color tags
Cheers!
P. A. [email protected] on 2009-12-02 at 10:13:
$ cucumber #=> color output
$ cucumber | less -R #=> monochrome
Ah now I see what you’re saying. We’re getting burned by this line:
http://github.com/aslakhellesoy/cucumber/blob/master/lib/cucumber/formatter/ansicolor.rb#L20
Term::ANSIColor.coloring = false if !STDOUT.tty? and not ENV.has_key?(“AUTOTEST”)
So, we can either feature request an override variable for this line, or
perhaps there is a way to trick a program that STDOUT is actually a
tty…?
Paul