summaryrefslogtreecommitdiffstats
path: root/lib/Reply/Plugin/Colors.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-05-30 04:41:11 -0500
committerJesse Luehrs <doy@tozt.net>2013-05-30 04:41:11 -0500
commitd8a90a03e9c5e8e2732374a10e0e79289ffb793c (patch)
tree98b6385d26dad2a14687c2c51d402c5b6ebdc837 /lib/Reply/Plugin/Colors.pm
parent69e4ff7c28debe5cae5bd505d5df12bd12bdd11a (diff)
downloadreply-d8a90a03e9c5e8e2732374a10e0e79289ffb793c.tar.gz
reply-d8a90a03e9c5e8e2732374a10e0e79289ffb793c.zip
App::REPL -> Reply
Diffstat (limited to 'lib/Reply/Plugin/Colors.pm')
-rw-r--r--lib/Reply/Plugin/Colors.pm66
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/Reply/Plugin/Colors.pm b/lib/Reply/Plugin/Colors.pm
new file mode 100644
index 0000000..199d41e
--- /dev/null
+++ b/lib/Reply/Plugin/Colors.pm
@@ -0,0 +1,66 @@
+package Reply::Plugin::Colors;
+use strict;
+use warnings;
+
+use base 'Reply::Plugin';
+
+use Term::ANSIColor;
+
+sub new {
+ my $class = shift;
+
+ my $self = $class->SUPER::new(@_);
+ $self->{error} = 'red';
+ $self->{warning} = 'yellow';
+ $self->{result} = 'green';
+
+ return $self;
+}
+
+sub compile {
+ my $self = shift;
+ my ($next, @args) = @_;
+
+ local $SIG{__WARN__} = sub { $self->print_warn(@_) };
+ $next->(@args);
+}
+
+sub execute {
+ my $self = shift;
+ my ($next, @args) = @_;
+
+ local $SIG{__WARN__} = sub { $self->print_warn(@_) };
+ $next->(@args);
+}
+
+sub print_error {
+ my $self = shift;
+ my ($next, $error) = @_;
+
+ print color($self->{error});
+ $next->($error);
+ local $| = 1;
+ print color('reset');
+}
+
+sub print_result {
+ my $self = shift;
+ my ($next, @result) = @_;
+
+ print color($self->{result});
+ $next->(@result);
+ local $| = 1;
+ print color('reset');
+}
+
+sub print_warn {
+ my $self = shift;
+ my ($warning) = @_;
+
+ print color($self->{warning});
+ print $warning;
+ local $| = 1;
+ print color('reset');
+}
+
+1;