Data-Printer
view release on metacpan or search on metacpan
lib/Data/Printer/Theme.pm view on Meta::CPAN
'bright_cyan' => 96, 'on_bright_cyan' => 106,
'bright_white' => 97, 'on_bright_white' => 107,
);
$color_code = "\e["
. join(';' => map $ansi_colors{$_}, split(/\s+/, $color_label))
. 'm'
;
}
else {
Data::Printer::Common::_warn($ddp, "invalid color '$color_label'");
}
return $color_code;
}
sub _rgb2short {
my ($r,$g,$b) = @_;
my @snaps = (47, 115, 155, 195, 235);
my @new;
foreach my $color ($r,$g,$b) {
my $big = 0;
foreach my $s (@snaps) {
$big++ if $s < $color;
}
push @new, $big
}
return $new[0]*36 + $new[1]*6 + $new[2] + 16
}
1;
__END__
=head1 NAME
Data::Printer::Theme - create your own color themes for DDP!
=head1 SYNOPSIS
package Data::Printer::Theme::MyCustomTheme;
sub colors {
return {
array => '#aabbcc', # array index numbers
number => '#aabbcc', # numbers
string => '#aabbcc', # strings
class => '#aabbcc', # class names
method => '#aabbcc', # method names
undef => '#aabbcc', # the 'undef' value
hash => '#aabbcc', # hash keys
regex => '#aabbcc', # regular expressions
code => '#aabbcc', # code references
glob => '#aabbcc', # globs (usually file handles)
vstring => '#aabbcc', # version strings (v5.30.1, etc)
lvalue => '#aabbcc', # lvalue label
format => '#aabbcc', # format type
true => '#aabbcc', # boolean type (true)
false => '#aabbcc', # boolean type (false)
repeated => '#aabbcc', # references to seen values
caller_info => '#aabbcc', # details on what's being printed
weak => '#aabbcc', # weak references flag
tainted => '#aabbcc', # tainted flag
unicode => '#aabbcc', # utf8 flag
escaped => '#aabbcc', # escaped characters (\t, \n, etc)
brackets => '#aabbcc', # (), {}, []
separator => '#aabbcc', # the "," between hash pairs, array elements, etc
quotes => '#aabbcc', # q(")
unknown => '#aabbcc', # any (potential) data type unknown to Data::Printer
};
}
1;
Then in your C<.dataprinter> file:
theme = MyCustomTheme
That's it! Alternatively, you can load it at runtime:
use DDP theme => 'MyCustomTheme';
=head1 DESCRIPTION
Data::Printer colorizes your output by default. Originally, the only way to
customize colors was to override the default ones. Data::Printer 1.0 introduced
themes, and now you can pick a theme or create your own.
Data::Printer comes with several themes for you to choose from:
=over 4
=item * L<Material|Data::Printer::Theme::Material> I<(the default)>
=for html <a href="https://metacpan.org/pod/Data::Printer::Theme::Material"><img style="height:50%" src="https://raw.githubusercontent.com/garu/Data-Printer/master/examples/theme-material.png" alt="Material Theme" /></a>
=item * L<Monokai|Data::Printer::Theme::Monokai>
=for html <a href="https://metacpan.org/pod/Data::Printer::Theme::Monokai"><img style="height:50%" src="https://raw.githubusercontent.com/garu/Data-Printer/master/examples/theme-monokai.png" alt="Monokai Theme" /></a>
=item * L<Solarized|Data::Printer::Theme::Solarized>
=for html <a href="https://metacpan.org/pod/Data::Printer::Theme::Solarized"><img style="height:50%" src="https://raw.githubusercontent.com/garu/Data-Printer/master/examples/theme-solarized.png" alt="Solarized Theme" /></a>
=item * L<Classic|Data::Printer::Theme::Classic> I<(original pre-1.0 colors)>
=for html <a href="https://metacpan.org/pod/Data::Printer::Theme::Classic"><img style="height:50%" src="https://raw.githubusercontent.com/garu/Data-Printer/master/examples/theme-classic.png" alt="Classic Theme" /></a>
=back
Run C<< examples/try_me.pl >> to see them in action on your own terminal!
=head1 CREATING YOUR THEMES
A theme is a module in the C<Data::Printer::Theme> namespace. It doesn't have
to inherit or load any module. All you have to do is implement a single
function, C<colors>, that returns a hash reference where keys are the
expected color labels, and values are the colors you want to use.
Feel free to copy & paste the code from the SYNOPSIS and customize at will :)
=head2 Customizing Colors
( run in 0.809 second using v1.01-cache-2.11-cpan-39bf76dae61 )