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


Manual Reference Pages  -  TERM::SCREENCOLOR (3)

.ds Aq ’

NAME

Term::ScreenColor - Term::Screen based screen positioning and coloring module

CONTENTS

SYNOPSIS

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);



DESCRIPTION

Term::ScreenColor adds ANSI coloring support, along with a few other useful methods, to those provided in Term::Screen.

PUBLIC INTERFACE

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:

<B> ANSI color names:B>
0clear
0reset
1ansibold22noansibold
3italic23noitalic
4underscore24nounderscore
5blink25noblink
7inverse27noinverse
8concealed28noconcealed
 30black40on_black
 31red41on_red
 32green42on_green
 33yellow43on_yellow
 34blue44on_blue
 35magenta45on_magenta
 36cyan46on_cyan
 37white47on_white

Additionally, the following names are understood (inherited from Term::Screen):

<B> termcap names:B>
 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);



FIXES TO Term::Screen

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.

PUBLIC INTERFACE

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:
o 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.
o 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).
o 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 <B>mdB> value from termcap, which usually turns on bold.
reverse() Sends the <B>mrB> value from termcap, which often turns on reverse text.
underline() Turns on underline using the <B>usB> 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 <B>normalB>, <B>boldB>, and <B>reverseB> 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.

AUTHOR

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

SEE ALSO

Term::Screen(3pm), Term::Cap(3pm), termcap(5), stty(1)
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 SCREENCOLOR (3) 2010-10-04

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