Search code examples
perlncursescurses

Color palette and more scale variations


I have here two code so you can help me understand...
Well at first my mask colors the "loading" shape. The initials rgbkmcw indicate their colors, red, ..., white. These are normal, already the CAPITAL LETTERS, correspond to bold (red = \e[31;10m; RED = \e[31;1m).
What I'm looking for is more variety of colors. Searching I found many, as well as for cyan.
cyan = "\e[36;10m", normal
cyann = "\e[36;1m", bold
cyanf = "\e[36;2m", weak
cyani = "\e[36;3m", italic
cyans = "\e[36;4m", underscore
cyanp = "\e[36;5m", flashing
cyanb = "\e[36;7m", background
cyanc = "\e[36;9m", canceled

How to use one of these colors in the mask abbreviating to some letter or number? Since everyady the each character in the mask represents the color of the corresponding character in the object.
For example: you want to use cyan italic; cyan normal and bold are already defined with c and C in the Term::Animation module.

So when trying to do 'ci' and run perl; return -> Use uninitialized value in stanza entry in /usr/local/share/perl/5.34.0/Term/Animation.pm
Why is there no italic cyan (ci) defined. I went to cd usr/local/share/perl/5.34.0/Term/Animation.pm
And there it creates lists mapping full color names (e.g. 'blue') and single character color IDs (e.g. 'b')

#---------- cd usr/local/share/perl/5.34.0/Term/----------
sub _color_list {
        my %color_n;
        my %color_i = (
                black   => 'k',
                white   => 'w',
                red     => 'r',
                green   => 'g',
                blue    => 'b',
                cyan    => 'c',
                magenta => 'm',
                yellow  => 'y',
        );

        for (keys %color_i) {
                $color_i{uc($_)} = uc($color_i{$_});
        }
        for (keys %color_i) {
                $color_n{$color_i{$_}} = $_;
                $color_n{$_} = $_;
                $color_n{uc($_)} = uc($_);
        }    
        for(qw{ k w r g b c m y }) {
                $color_i{$_} = $_;
                $color_i{uc($_)} = uc($_);
        }    
        return (\%color_n, \%color_i);
}  

I need to include more color variations, like this color.
So, how to add directly in the Animation.pm module, a color like cyan italic = \e[36;3m; ?
I tried querying the Term::Animation/COLOR section in link metacpan but the page returns "Not Found".

#---------------------MY MASK--------------------------  
use strict;
use warnings;
# you don't have to include Curses, but it is handy so we
# can use halfdelay and getch below.
use Curses;
use Term::Animation 2.0;
# this creates a full screen animation object. you can also
# pass a curses window as an argument to new()
my $s = Term::Animation->new();

$s->color(1);
my $phrase = "Press q to exit";
# a few simple ASCII art objects to move around

my @loading= (q{
================
});
my @mask = (q{
RrBbWwKkYyMmCcGg
});
$s->new_entity(
        shape           => \@loading,
        position        => [ 30, 2, 20],
        callback_args   => [0,0,0,1],
        color   => \@mask,
);
halfdelay( 2 );
for(1..500) {

$s->animate();
my $in = lc( getch() );
if($in eq 'q') { last; }
}

use strict;
use warnings;
use feature 'say';

my $cyan  = "\e[36;10m";#normal
my $cyann = "\e[36;1m"; #bold
my $cyanf = "\e[36;2m"; #weak

my $off = "\e[m";       #off

say("$cyan    cyan   $off");
say("$cyann   cyann  $off");
say("$cyanf   cyanf  $off");

Solution

  • How to use one of these colors in the mask abbreviating to some letter or number?

    Currently Term::Animation only supports 8 colors, so you need to modify the source to do this. Here is an example:

    $ git clone https://github.com/hakonhagland/perl-term-animation.git 
    $ cd perl-term-animation/
    $ git fetch origin colors:colors
    $ git checkout colors
    $ cpanm --installdeps .
    $ perl Makefile.PL
    $ make
    $ make test
    $ make install  # <- or use "sudo make install" if you are using the system perl
    

    A simple test program to test the modified Term::Animation module:

    use strict;
    use warnings;
    use Curses;
    use Term::Animation 2.0;
    
    my $s = Term::Animation->new();
    $s->color2(1);  # <-- uses the color2 type mask
    my @loading= (q{
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    });
    my @mask = (q{
    abcdefghijklmnopqrstuvwxyz
    });
    
    $s->new_entity(
            shape           => \@loading,
            position        => [ 30, 2, 20],
            callback_args   => [0,0,0,1],
            color   => \@mask,
    );
    halfdelay( 2 );
    for(1..500) {
        $s->animate();
        my $in = lc( getch() );
        if($in eq 'q') { last; }
    }
    

    With this test program I get the following output (screen shot):

    enter image description here