Term::ScreenColor - Term::Screen based screen positioning and coloring module
A Term::Screen based screen positioning module with ANSI color support.
use Term::ScreenColor; $scr = new Term::ScreenColor; $scr->colorizable(1); $scr->at(2,0)->red()->on_yellow()->puts("Hello, Tau Ceti!"); $scr->putcolored('cyan bold on blue', 'Betelgeuse'); $scr->putcolored('36;1;44', 'Altair');
Term::ScreenColor adds ANSI coloring support, along with a few other useful methods, to those provided in Term::Screen.
Most methods return the Term::ScreenColor object so you can string things together, e.g.
In addition to the methods described in Term::Screen(3pm), Term::ScreenColor offers the following methods:
Creates a new Term::ScreenColor object. Note that the constructor of the inherited class Term::Screen homes the cursor and switches the terminal to raw input mode.
Returns (if called with no arguments) or sets (if called with one boolean argument) whether the terminal is believed to support ANSI color codes. If this is set to false, no ANSI codes will be printed or generated. This provides an easy way for turning color on/off.
Note that the constructor above takes an initial guess at whether the terminal supports color (based on the value of the
TERM environment variable).
Prints an ANSI escape sequence for a specific color.
The color names understood are:
ANSI color names: ----------------------------------- 0 clear 0 reset 1 ansibold 22 noansibold 3 italic 23 noitalic 4 underscore 24 nounderscore 5 blink 25 noblink 7 inverse 27 noinverse 8 concealed 28 noconcealed ----------------------------------- 30 black 40 on_black 31 red 41 on_red 32 green 42 on_green 33 yellow 43 on_yellow 34 blue 44 on_blue 35 magenta 45 on_magenta 36 cyan 46 on_cyan 37 white 47 on_white ------------------------------------
Additionally, the following names are understood (inherited from Term::Screen):
termcap names: --------------- normal bold underline reverse ---------------
These termcap names send termcap-based escapes, which are not considered 'colors' and can therefore not be turned off by colorizable().
As of version 1.12, underline() is termcap-based instead of ANSI-based.
Creates a string containing the escape codes corresponding to the color names or numbers given.
If the terminal is considered to be colorizable, This method will translate any termcap-names to their ANSI equivalents. This algorithm was chosen to improve performance.
$scr->colorizable(1); $scr->color2esc('bold yellow'); # returns "\e[1;33m" $scr->color2esc('blue reverse'); # returns "\e[34;7m" $scr->color2esc('yellow on red'); # returns "\e[33;41m" $scr->color2esc('37;42'); # returns "\e[37;42m"
If the terminal is not colorizable, the ANSI names are discarded and only the termcap-names are respected. They will send the escape sequences as defined in the termcap database.
$scr->colorizable(0); $scr->color2esc('bold yellow'); # returns 'md' from termcap, probably "\e[1m" $scr->color2esc('blue reverse'); # returns 'mr' from termcap, probably "\e[7m" $scr->color2esc('yellow on red'); # returns ""
(Deprecated). Identical to putcolor($colorstring).
Prints the escape sequence corresponding to this color string, in other words: the escape sequence that color2esc() generates.
Returns a string containing a concatenation of the string parts, wrapped in ANSI color sequences, using the first argument as color specification.
# the next two lines return "\e[36;1;44mSirius\e[0m" $scr->colored('cyan bold on blue', 'Sirius'); $scr->colored('36;1;44', 'Sirius');
Identical to puts(), but wraps its arguments in ANSI color sequences first, using the first argument as color specification.
# the next two lines print "\e[32;40mSirius\e[0m" $scr->colored('green on black', 'Sirius'); $scr->colored('32;40', 'Sirius');
As of version 1.11, Term::ScreenColor is bundled with some bugfixes, enhancements and convenience functions that should have gone in Term::Screen. They are therefore contained in a separate package Term::Screen::Fixes.
Term::Screen::Fixes offers the following methods:
Creates a new object. Initializes a timeout property, used for keys that generate escape sequences.
Returns (if called with no arguments) or sets (if called with one float argument) the function key timeout.
This duplicates the functionality of Term::Screen::getch(), but makes the following improvements:
Sends the escape sequence to turn off any highlightling (bold, reverse).
Sends the md value from termcap, which usually turns on bold.
Sends the mr value from termcap, which often turns on reverse text.
Turns on underline using the us value from termcap.
Sends the visual bell escape sequence to the terminal.
Return the termcap definitions for normal, bold, reverse, underline and visual bell.
It was attested that on OpenSolaris 11, Term::Cap cannot provide the properties normal, bold, and reverse because there is no termcap and
infocmp -C does not provide these properties (even though
infocmp does). In that case, fall back on terminfo.
Sets raw input mode using stty(1).
Sets cooked input mode using stty(1).
Duplicates the functionality of Term::Screen::flush_input(), but replaces getc() with sysread().
Adds more function key escape sequences.
Rene Uittenbogaard (firstname.lastname@example.org)
Term::ScreenColor was based on:
Originally by Mark Kaehny (email@example.com), now maintained by Jonathan Stowe (firstname.lastname@example.org).
By Russ Allbery (email@example.com) and Zenin (firstname.lastname@example.org).