René Uittenbogaard > Term-ScreenColor-1.13a > Term::ScreenColor

Download:
Term-ScreenColor-1.13a.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.13   Source   Latest Release: Term-ScreenColor-1.20

NAME ^

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

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 (using the TERM 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.

Examples:

    $scr->color2esc('bold yellow');   # returns "\e[1;33m"
    $scr->color2esc('yellow on red'); # returns "\e[33;41m"
    $scr->color2esc('33;41');         # returns "\e[33;41m"

Note that this method translates the termcap-names to their ANSI equivalents (that respect the colorizable() setting). This algorithm was chosen to prevent a huge performance penalty if termcap sequences had to be sent.

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:

  • 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.
flash()

Sends the visual bell escape sequence to the terminal.

underline()

Turns on underline using the us value from termcap.

bold2esc()
reverse2esc()
underline2esc()
normal2esc()

Return the termcap definitions for bold, reverse, underline and normal.

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)

syntax highlighting: