Term::ANSIColor::Conditional - Colorize text only if color is enabled
This document describes version 0.009 of Term::ANSIColor::Conditional (from Perl distribution Term-ANSIColor-Conditional), released on 2021-06-01.
Use as you would Term::ANSIColor.
This module is a wrapper for Term::ANSIColor. If color is enabled then everything is the same as Term::ANSIColor. If color is disabled, then color() will emit empty string and colored() will not colorize input text.
color()
colored()
How to determine "color is enabled":
If package variable $Term::ANSIColor::Conditional::COLOR is defined, use that.
$Term::ANSIColor::Conditional::COLOR
Otherwise, check if NO_COLOR environment variable exists. If yes, color is disabled.
NO_COLOR
Otherwise, check if COLOR environment variable is defined and use that.
COLOR
Otherwise, check if (-t STDOUT) is true (interactive terminal). If yes, color is enabled.
Otherwise, color is disabled.
Note that Term::ANSIColor already supports conditional color via the ANSI_COLORS_DISABLED and NO_COLOR environment variables, but it does not check for interactive terminal or the COLOR environment variable.
ANSI_COLORS_DISABLED
For more information, see https://no-color.org.
Please visit the project's homepage at https://metacpan.org/release/Term-ANSIColor-Conditional.
Source repository is at https://github.com/perlancar/perl-Term-ANSIColor-Conditional.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Term-ANSIColor-Conditional
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Term::ANSIColor
Term::ANSIColor::Patch::Conditional, patch version for this module.
These modules also respect the NO_COLOR and/or the COLOR environment variable: Color::ANSI::Util, Text::ANSITable, Data::Dump::Color, App::diffwc, App::rsynccolor.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2021, 2020, 2018, 2017 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Term::ANSIColor::Conditional, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::ANSIColor::Conditional
CPAN shell
perl -MCPAN -e shell install Term::ANSIColor::Conditional
For more information on module installation, please visit the detailed CPAN module installation guide.