use Data::Printer theme => 'Monokai'; # sets a theme my $var = ... p $var; # colored if terminal supports it p $var, colored => 'auto'; # same! it's the default :) p $var, colored => 1; # force colored output p $var, colored => 0; # NO color my $dump = np $var; # NO color $dump = np $var, colored => 1; # force colored output
Data::Printer's default color mode is 'auto', meaning it will colorize the output only when all conditions below are met:
* There is no ANSI_COLORS_DISABLED environment variable; * The output is going to the terminal, not just returned; * The output handle (STDERR by default) is not being piped; * Your terminal supports colors (most do).
To never colorize anything, just set `colored` to 0.
Setting any color to undef means "Don't colorize this". Otherwise, the color is a string which can be one of the following:
undef
Only 8 named colors are supported:
black, red, green, yellow, blue, magenta, cyan, white
and their bright_XXX, on_XXX and on_bright_XXX variants.
bright_XXX
on_XXX
on_bright_XXX
Those are provided only as backards compatibility with older versions of Data::Printer and, because of their limitation, we encourage you to try and use one of the other representations.
You may provide any SGR escape sequence, and they will be honored as long as you use double quotes (e.g. "\e[38;5;196m"). You may use this to achieve extra control like blinking, etc. Note, however, that some terminals may not support them.
"\e[38;5;196m"
'rgb(0,255,30)' '#00FF3B'
NOTE: There may not be a real 1:1 conversion between RGB and terminal colors. In those cases we use approximation to achieve the closest option.
For a list of all available themes:
my @themes = Data::Printer::available_themes();
TODO: image of themes, from github.
Run examples/color_themes.pl to see them in action on your own terminal!
examples/color_themes.pl
You just have to create a package named Data::Printer::Theme::MyTheme, where MyTheme is the name of your theme.
Data::Printer::Theme::MyTheme
MyTheme
That package needs to implement a single function called `colors`, that returns the same hash reference as a regular Data::Printer call:
sub colors { return { } }
To install Data::Printer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Printer
CPAN shell
perl -MCPAN -e shell install Data::Printer
For more information on module installation, please visit the detailed CPAN module installation guide.