roadrider has asked for the wisdom of the Perl Monks concerning the following question:

I have Term::ANSIColor installed and it works with one liners, i.e,
perl -e 'use Term::ANSIColor; print color "blue"; print "Hello world!\ +n"; print color "reset";'
However, neither perlcritic --color someFile.pl nor perlcritic --color-severity-high='magenta' someFile.pl seem to work. My terminal can display color (grep --color works). I have tried changing the color settings in my xterm profile from Linux console to Xterm but still no joy. What am I missing?

Replies are listed 'Best First'.
Re: perlcritic --color option not working
by toolic (Bishop) on Dec 16, 2011 at 20:20 UTC
    Did you set color = 0 in your .perlcriticrc file?

    I get red when I run this command:

    $ echo foo | perlcritic --noprofile Code before strictures are enabled at line 1, column 1. See page 429 +of PBP. (Severity: 5)
    See what's in your profile using:
    perlcritic --profile-proto | grep color
      Thanks for your reply. Actually my .perlcriticrc has specific colors set for the various severity levels. I tried using --noprofile but still no colors appear. I also tried commenting out the color specifications in my profile (to get the defaults) and that didn't work either.
        Do you have recent versions of perl and Perl::Critic?
        perl -v perl -MPerl::Critic -le 'print $Perl::Critic::VERSION'
        Take a look through the bug list. I didn't see anything related to color, but maybe you can get some debug tips. (Tip #11 from the Basic debugging checklist.)
Re: perlcritic --color option not working
by Anonymous Monk on Dec 17, 2011 at 21:55 UTC

    According to the source code of Perl-Critic-1.116, you need to have Term::ANSIColor version 2.02 or later for colorization. I believe that version provides a mechanism for validating your custom colors, which perlcritic wants to use.

    If I remember correctly, only the severity 4 and 5 violations are colorized by default. So if you only have severity 1, 2, or 3 violations then you won't see any color. Unless you use --color-severity-(medium|low|lowest) to change the default colors for those.

      Yes, this could be the problem. Our version of the module is 2.00. I will try upgrading it. Thanks!
Re: perlcritic --color option not working
by Khen1950fx (Canon) on Dec 18, 2011 at 14:30 UTC
    Since you're having a problem with magenta, check that magenta is valid, then try printing it out:
    #!/usr/bin/perl -l use strict; use warnings; use Term::ANSIColor qw(colorvalid); use Term::ANSIScreen qw/:color :constants/; my $valid = colorvalid ('magenta'); print "Color string is ", $valid ? "valid" : "invalid"; print MAGENTA . "Magenta" . RESET;

    See:

    Term::ANSIColor
    Term::ANSIScreen

    Additional tests:

    ansicolor
    colortest

    To run ansicolor:
    cat ansicolor
    colortest prints out all 256 xterm colors.
      All of the colors work. I've tested them independently of perlcritic.