summaryrefslogtreecommitdiffstats
path: root/lib/Reply/Plugin/Colors.pm
diff options
context:
space:
mode:
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;