|
Term::ANSIScreen - Terminal control using ANSI escape sequences. |
:color function set (exported by default):constants function set:cursor function set:screen function set:keyboard function set
Term::ANSIScreen - Terminal control using ANSI escape sequences.
# qw/:color/ is exported by default, i.e. color() & colored()
use Term::ANSIScreen qw/:color :cursor :screen :keyboard/;
print setmode(1), setkey('a','b');
print "40x25 mode now, with 'a' mapped to 'b'.";
<STDIN>; resetkey; setmode 3; cls;
locate 1, 1; print "@ This is (1,1)", savepos;
print locate(24,60), "@ This is (24,60)"; loadpos;
print down(2), clline, "@ This is (3,15)\n";
color 'black on white'; clline;
print "This line is black on white.\n";
print color 'reset'; print "This text is normal.\n";
print colored ("This text is bold blue.\n", 'bold blue');
print "This text is normal.\n";
print colored ['bold blue'], "This text is bold blue.\n";
print "This text is normal.\n";
use Term::ANSIScreen qw/:constants/; # constants mode
print BLUE ON GREEN . "Blue on green.\n";
$Term::ANSIScreen::AUTORESET = 1;
print BOLD GREEN . ON_BLUE "Bold green on blue.", CLEAR;
print "\nThis text is normal.\n";
Term::ANSIScreen is a superset of Term::ANSIColor. In addition
to color-sequence generating subroutines exported by :color
and :constants, this module also features :cursor for
cursor positioning, :screen for screen control, as well
as :keyboard for key mapping.
:color function set (exported by default)Term::ANSIScreen recognizes (case-insensitively) following color attributes: clear, reset, bold, underline, underscore, blink, reverse, concealed, black, red, green, yellow, blue, magenta, on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, and on_white.
The color alone sets the foreground color, and on_color sets the background color. You may also use on_color without the underscore, e.g. ``black on white''.
Alternately, you can pass a reference to an array as the first argument, and then the contents of that array will be taken as attributes and color codes and the remainder of the arguments as text to colorize.
Normally, this function just puts attribute codes at the beginning and end of the string, but if you set $Term::ANSIScreen::EACHLINE to some string, that string will be considered the line delimiter and the attribute will be set at the beginning of each line of the passed string and reset at the end of each line. This is often desirable if the output is being sent to a program like a pager, which can be confused by attributes that span lines.
Normally you'll want to set $Term::ANSIColor::EACHLINE to
"\n" to use this feature.
:constants function setIf you import :constants you can use the constants CLEAR,
RESET, BOLD, UNDERLINE, UNDERSCORE, BLINK, REVERSE, CONCEALED,
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, ON_BLACK, ON_RED,
ON_GREEN, ON_YELLOW, ON_BLUE, ON_MAGENTA, ON_CYAN, and ON_WHITE
directly. These are the same as color('attribute') and can be
used if you prefer typing:
print BOLD BLUE ON_WHITE "Text\n", RESET;
print BOLD BLUE ON WHITE "Text\n", RESET; # _ is optional
to print colored (``Text\n'', 'bold blue on_white');
When using the constants, if you don't want to have to remember
to add the , RESET at the end of each print line, you can set
$Term::ANSIColor::AUTORESET to a true value. Then, the display
mode will automatically be reset if there is no comma after the
constant. In other words, with that variable set:
print BOLD BLUE "Text\n";
will reset the display mode afterwards, whereas:
print BOLD, BLUE, "Text\n";
will not.
:cursor function set
:screen function set0: 40 x 25 x 2 (text) 1: 40 x 25 x 16 (text) 2: 80 x 25 x 2 (text) 3: 80 x 25 x 16 (text) 4: 320 x 200 x 4 5: 320 x 200 x 2 6: 640 x 200 x 2 7: Enables line wrapping 13: 320 x 200 x 4 14: 640 x 200 x 16 15: 640 x 350 x 2 16: 640 x 350 x 16 17: 640 x 480 x 2 18: 640 x 480 x 16 19: 320 x 200 x 256
:keyboard function set
color() or
colored().
print FOOBAR "This text is color FOOBAR\n";
It's probably better to always use commas after constant names in order to force the next error.
print FOOBAR, "This text is color FOOBAR\n";
Generating this fatal compile error is one of the main advantages of using the constants interface, since you'll immediately know if you mistype a color name.
$Foobar = FOOBAR . "This line should be blue\n";
or:
@Foobar = FOOBAR, "This line should be blue\n";
This will only show up under use strict (another good reason to run under use strict).
Original idea (using constants) by Zenin (zenin@best.com), reimplemented using subs by Russ Allbery (rra@stanford.edu), and then combined with the original idea by Russ with input from Zenin to Term::ANSIColor. Screen mode and keyboard mapping codes were added by Autrijus Tang, along with revised code and documentation.
Copyright 2001 by Autrijus Tang <autrijus@autrijus.org>. Based on works of Zenin (zenin@best.com), Russ Allbery (rra@stanford.edu)
All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Term::ANSIScreen - Terminal control using ANSI escape sequences. |