I love Perl's Term::ANSIColor
module but is it possible to print out colours other than the ones provided?
I'm trying to print out words with a range between deep red and bright green, with a decent number of steps between them. Is there a way to supply an RGB value or something to change the color of the text?
You use Term::ExtendedColor. You can use 256 colors by this module.
A few terminals even accept full 8-bit RGB colour specifications.
$ perl -E 'say "\e[38:2:255:100:80mHello\e[m"'
Hello
This may be printed in rgb(255,100,80)
colour pink. Depends on your terminal.
As a way to obtain xterm256 colour values out of arbitrary RGB combinations, you might also like Convert::Color
use strict;
use warnings;
use Convert::Color;
use Convert::Color::XTerm;
foreach my $hue ( map { $_ * 15 } 0 .. 120/15 ) {
my $c = Convert::Color->new( "hsv:$hue,1,1" );
my $index = $c->as_xterm->index;
print "\e[38:5:${index}mHue=$hue\e[m\n";
}
I'd paste the output here but it's hard to convey the colours in a comment :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With