App-Adenosine

 view release on metacpan or  search on metacpan

lib/App/Adenosine/Plugin/Rainbow.pm  view on Meta::CPAN

package App::Adenosine::Plugin::Rainbow;
$App::Adenosine::Plugin::Rainbow::VERSION = '2.002000';
use Moo;

with 'App::Adenosine::Role::FiltersStdErr';
use Module::Runtime 'require_module';
use Try::Tiny;

try {
   require_module('Term::ExtendedColor')
} catch {
   die <<"ERR"
Term::ExtendedColor must be installed to use ::Rainbow

original error: $_
ERR
};

our %old_colormap = (
   red => 1,
   green => 2,
   yellow => 3,
   blue => 4,
   purple => 5,
   cyan => 6,
   white => 7,
   gray => 8,
   bright_red => 9,
   bright_green => 10,
   bright_yellow => 11,
   bright_blue => 12,
   magenta => 13,
   bright_cyan => 14,
   bright_white => 15,
);

sub colorize {
   my ($self, $arg, $str) = @_;

   $arg = { fg => $arg } unless ref $arg;

   for (qw(fg bg)) {
      $arg->{$_} = $old_colormap{$arg->{$_}}
         if $arg->{$_} && exists $old_colormap{$arg->{$_}}
   }

   $str = Term::ExtendedColor::fg($arg->{fg}, $str ) if $arg->{fg};
   $str = Term::ExtendedColor::bg($arg->{bg}, $str ) if $arg->{bg};
   $str = Term::ExtendedColor::bold($str           ) if $arg->{bold};
   $str = Term::ExtendedColor::italic($str         ) if $arg->{italic};
   $str = Term::ExtendedColor::underline($str      ) if $arg->{underline};

   return $str;
}

has response_header_colon_color => (
   is => 'ro',
   default => sub { 'blue' },
);

has response_header_name_color => (
   is => 'ro',
   default => sub { 'cyan' },
);

has response_header_value_color => (
   is => 'ro',



( run in 2.640 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )