Reputation: 29116
I wrote a Perl program that colorize its output.
Unfortunately I also have an interpreter that runs my program and display its output with no understanding of any ANSI escape sequences.
What is the correct way to simply bypass Term::ANSIColor
? It would be awful to always treat both cases for each say
or print
statement i.e. say ($ENV{'TERM'} ne 'NONE')?colored('foo', green):'foo';
Any suggestion is welcome.
Upvotes: 4
Views: 380
Reputation: 24073
Use the ANSI_COLORS_DISABLED
environment variable:
ANSI_COLORS_DISABLED
If this environment variable is set to a true value, all of the functions defined by this module (color(), colored(), and all of the constants not previously used in the program) will not output any escape sequences and instead will just return the empty string or pass through the original text as appropriate. This is intended to support easy use of scripts using this module on platforms that don't support ANSI escape sequences.
Upvotes: 4