GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
ScreenColor(3) User Contributed Perl Documentation ScreenColor(3)

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.

    $scr->at(2,3)->cyan()->on_white()->puts("hello");

In addition to the methods described in Term::Screen(3pm), Term::ScreenColor offers the following methods:

new()
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.
colorizable()
colorizable($boolean)
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).

black()
red()
on_white()
on_cyan()
inverse()
etc.

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.

color2esc($colorstring)
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.

Examples:

    $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.

Examples:

    $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 ""
    
color($colorstring)
(Deprecated). Identical to putcolor($colorstring).
putcolor($colorstring)
Prints the escape sequence corresponding to this color string, in other words: the escape sequence that color2esc() generates.
colored($colorstring, @strings)
Returns a string containing a concatenation of the string parts, wrapped in ANSI color sequences, using the first argument as color specification.

Example:

   # the next two lines return "\e[36;1;44mSirius\e[0m"
   $scr->colored('cyan bold on blue', 'Sirius');
   $scr->colored('36;1;44', 'Sirius');
    
putcolored($colorstring, @strings)
Identical to puts(), but wraps its arguments in ANSI color sequences first, using the first argument as color specification.

Example:

   # 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:
new()
Creates a new object. Initializes a timeout property, used for keys that generate escape sequences.
timeout()
timeout($float)
Returns (if called with no arguments) or sets (if called with one float argument) the function key timeout.
getch()
This duplicates the functionality of Term::Screen::getch(), but makes the following improvements:
  • getc() was replaced by sysread(). Since getc() does internal buffering, it does not work well with select(). This led in certain cases to the application not receiving input as soon as it was available.
  • If the received character(s) started off as a possible function key escape sequence, but turn out not to be one after all, then the keys are put back in the input buffer in the correct order. (Term::Screen::getch() put them back at the wrong end of the buffer).
  • If the first received character(s) are part of a possible function key escape sequence, it will wait the timeout number of seconds for a next character. This eliminates the need to press escape twice.
normal()
Sends the escape sequence to turn off any highlightling (bold, reverse).
bold()
Sends the md value from termcap, which usually turns on bold.
reverse()
Sends the mr value from termcap, which often turns on reverse text.
underline()
Turns on underline using the us value from termcap.
flash()
Sends the visual bell escape sequence to the terminal.
normal2esc()
bold2esc()
reverse2esc()
underline2esc()
flash2esc()
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.

raw()
Sets raw input mode using stty(1).
cooked()
Sets cooked input mode using stty(1).
flush_input()
Duplicates the functionality of Term::Screen::flush_input(), but replaces getc() with sysread().
get_more_fn_keys()
Adds more function key escape sequences.

Rene Uittenbogaard (ruittenb@users.sourceforge.net)

Term::ScreenColor was based on:

Term::Screen
Originally by Mark Kaehny (kaehny@execpc.com), now maintained by Jonathan Stowe (jns@gellyfish.co.uk).
Term::ANSIColor
By Russ Allbery (rra@cs.stanford.edu) and Zenin (zenin@best.com).

Term::Screen(3pm), Term::Cap(3pm), termcap(5), stty(1)
2010-10-04 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.