Print more than ANSI color values ​​in Perl

I like the Perl Term::ANSIColor , but is it possible to print colors other than those provided?

I am trying to print words with a range between dark red and bright green, with enough steps between them. Is there a way to provide an RGB value or something to change the color of the text?

+6
source share
2 answers

You are using Term :: ExtendedColor . You can use 256 colors with this module.

+10
source

Several terminals even accept full 8-bit RGB color specifications.

 $ perl -E 'say "\e[38:2:255:100:80mHello\e[m"' Hello 

It can be printed in rgb(255,100,80) color pink. Depends on your terminal.

As a way to get xterm256 color values ​​from 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 would insert the output here, but it is difficult to convey the colors in the comments :)

+1
source

Source: https://habr.com/ru/post/909260/


All Articles