3 package Devel::REPL::Plugin::Colors;
4 # ABSTRACT: Add color to return values, warnings, and errors
6 our $VERSION = '1.003030';
8 use Devel::REPL::Plugin;
10 use namespace::autoclean;
13 is => 'rw', lazy => 1,
18 is => 'rw', lazy => 1,
19 default => 'bold red',
22 around format_error => sub {
25 return color($self->error_color)
30 # we can't just munge @_ because that screws up DDS
31 around format_result => sub {
34 no warnings 'uninitialized';
36 color($self->normal_color),
42 # make arbitrary warns colored -- somewhat difficult because warn doesn't
43 # get $self, so we localize $SIG{__WARN__} during eval so it can get
50 local $SIG{__WARN__} = sub {
53 warn color($self->error_color || 'bold red')
62 around compile => \&_wrap_warn;
63 around execute => \&_wrap_warn;
75 my $repl = Devel::REPL->new;
76 $repl->load_plugin('LexEnv');
77 $repl->load_plugin('History');
78 $repl->load_plugin('Colors');
83 Colors are very pretty.
85 This plugin causes certain prints, warns, and errors to be colored. Generally
86 the return value(s) of each line will be colored green (you can override this
87 by setting C<< $_REPL->normal_color >> in your rcfile). Warnings and
88 compile/runtime errors will be colored with C<< $_REPL->error_color >>. This
89 plugin uses L<Term::ANSIColor>, so consult that module for valid colors. The
90 defaults are actually 'green' and 'bold red'.
98 Shawn M Moore, C<< <sartak at gmail dot com> >>
100 =head1 COPYRIGHT AND LICENSE
102 Copyright (C) 2007 by Shawn M Moore
104 This library is free software; you can redistribute it and/or modify
105 it under the same terms as Perl itself.