If you want to colorize screen output in your programs, chances are you’ve encountered the core Term::ANSIColor module.
It works just as expected, which means it deals with the standard ANSI colors. Nowadays, most terminals support the extended colorset as well, and I was quite surprised there wasn’t a module dealing with this already.
I present to you Term::ExtendedColor.
As of today, it’s really hard to find a terminal that does not support these extended colors.
The biggest obstacle I encountered was how to name the colors. With a total of 240 additional colors with about 30 shades of green, 20 shades of yellow and so on, it wasn’t obvious.
Then I thought of the X11 color names
- they surely must match! They didn’t.
So the solution was pretty simple - create one table per base color ( green, blue, yellow ), make the brightest shade the first element and name the colors by their base color plus index.
If you happen to know of a better way to solve this, please let me know.
The interface is almost identical to the functional interface from Term::ANSIColor, with a few exceptions.
First, there’s no need to separate a color() and colored() function.
Second, two separate functions are exported to deal with foreground and background attributes.
The colorstrip() function in Term::ANSIColor is called uncolor().
set_color() allows you to change mapped colors, ANSI as well as the extended ones. This is the same technique that’s used in colorcoke.
get_colors() returns a hash reference with all available colors:
lookup() allows you to lookup a color by their index.