NAME
Term::VT102 - a class to emulate a DEC VT102 terminal
SYNOPSIS
use Term::VT102;
my $vt = Term::VT102->new ('cols' => 80, 'rows' => 24);
while (<>) { $vt->process ($_); }
DESCRIPTION
The VT102 class provides emulation of most of the functions of a DEC VT102 terminal. Once initialised, data passed to a VT102 object is processed and the in-memory "screen" modified accordingly. This "screen" can be interrogated by the external program in a variety of ways.
This allows your program to interface with full-screen console programs by running them in a subprocess and passing their output to a VT102 class. You can then see what the application has written on the screen by querying the class appropriately.
OPTIONS
Setting cols or rows in the new() hash allows you to change the size of the terminal being emulated. If you do not specify a size, the default is 80 columns by 24 rows.
After initialisation, you can read and set the following terminal options using the option_read() and option_set() methods:
LINEWRAP line wrapping; 1=on, 0=off. Default is OFF.
LFTOCRLF treat LF (\n) as CRLF (\r\n); 1=on, 0=off. Default OFF.
METHODS
The following methods are provided:
- attr_pack ($fg,$bg,$bo,$fa,$st,$ul,$bl,$rv)
-
Returns the packed version of the given attribute settings, which are given in the same order as returned by attr_unpack. The packed version will be a binary string not longer than 2 bytes.
- attr_unpack ($data)
-
Returns a list of the contents of the given packed attribute settings, of the form ($fg,$bg,$bo,$fa,$st,$ul,$bl,$rv).
$fg and $bg are the ANSI foreground and background text colours, and $bo, $fa, $st, $ul, $bl, and $rv are flags (1 = on, 0 = off) for bold, faint, standout, underline, blink and reverse respectively.
- callback_call ($name, $par1, $par2)
-
Calls the callback $name (eg 'ROWCHANGE') with parameters $par1 and $par2, as if the VT102 module had called it. Does nothing if that callback has not been set with callback_set ().
- callback_set ($callback, $ref)
-
Sets the callback callback to function reference ref. See the section on CALLBACKS below.
- new (%config)
-
Returns a new VT102 object with options specified in %config (see the OPTIONS section for details).
- option_read ($option)
-
Returns the current value of terminal option $option (see OPTIONS for details), or undef if that option does not exist. Note that you cannot read the terminal size with this call; use size() for that.
- option_set ($option, $value)
-
Sets the current value of terminal option $option to $value, returning the old value or undef if no such terminal option exists or you have specified an undefined $value. Note that you cannot resize the terminal with this call; use resize() for that.
- process ($string)
-
Processes the string $string (which can be zero-length), updating the VT102 object accordingly and calling any necessary callbacks on the way.
- resize ($cols, $rows)
-
Resizes the VT102 terminal to cols columns by rows rows, eg $vt->resize (80, 24). The virtual screen is cleared first.
- reset ()
-
Resets the object to its "power-on" state.
- row_attr ($row)
-
Returns the attributes for row $row (or undef if out of range) as a string of packed attributes, each character cell's attributes being 2 bytes long. To unpack the attributes for a given cell, use substr(), eg $attr=substr($row,4,2) would set $attr to the attributes for cell 3 (steps of 2: 0 .. 2 .. 4, so 4 means the 3rd character). You would then use the attr_unpack() method to unpack that character cell's attributes.
- row_plaintext ($row)
-
As row_text(), but unused characters are represented as spaces instead of as \0.
- row_text ($row)
-
Returns the textual contents of row $row (or undef if out of range), with totally unused characters being represented as NULL (\0).
- size ()
-
Return a pair of values (columns,rows) denoting the size of the terminal in the VT102 object.
- status ()
-
Return a list of values ($X,$Y,$attr,$ti,$ic), where $X and $Y are the cursor co-ordinates (1,1 = top left), $attr is a packed version of the current attributes (see attr_unpack), $ti is the xterm window title, and $ic is the xterm window icon name.
- version ()
-
Return the version of the VT102 module being used.
CALLBACKS
Callbacks are the processing loop's way of letting your main program know that something has happened. They are called while in a process() loop.
To specify a callback, use the callback_set interface, giving a reference to the function to call. Your function should take four scalar arguments: the VT102 object being processed, the name of the callback, and two arguments whose value depends on the callback, as shown below.
The name of the callback is passed to the callback function so that you can have one function to handle all callbacks if you wish.
Available callback names are:
BELL BEL (beep, \007) character received
CLEAR screen about to be cleared
OUTPUT data (arg1) to be sent back to data source
ROWCHANGE screen row (row number is argument 1) content has changed
SCROLL_DOWN about to scroll down (arg1=top row, arg2=num to scroll)
SCROLL_UP about to scroll up (ditto)
UNKNOWN unknown/unsupported code (arg1=name, arg2=code/sequence)
XICONNAME xterm icon name to be changed to arg1
XWINTITLE xterm title name to be changed to arg2
Note that the wording of the above is significant in terms of exactly when the callback is called. For instance, CLEAR is called just before the screen is cleared, whereas ROWCHANGE is called after the given row has been changed.
A good callback handler for OUTPUT is to simply syswrite() argument 1 to your data source - eg if you're reading from a telnet session, write that argument straight to it. It is used for cursor position request responses and suchlike.
Note that SCROLL_DOWN is called when scrolling down, so text is about to move UP the screen; arg1 will be the row number of the bottom of the scrolling region, and arg2 will be the number of rows to be scrolled. Likewise, SCROLL_UP is called when text is about to move down; arg1 will be the row number of the top of the scrolling region.
Finally, note that ROWCHANGE is only triggered when text is being entered; screen scrolling or screen clearance does not trigger it, that would trigger a SCROLL_DOWN or SCROLL_UP or CLEAR. Line or character insertion or deletion will cause one or more ROWCHANGE callbacks, however.
SUPPORTED CODES
The following sequences are supported:
007 (BEL) beep
010 (BS) backspace
011 (HT) horizontal tab to next tab stop
012 (LF) line feed
013 (VT) line feed
014 (FF) line feed
015 (CR) carriage return
030 (CAN) interrupt escape sequence
032 (SUB) interrupt escape sequence
033 (ESC) start escape sequence
177 (DEL) ignored
233 (CSI) same as ESC [
CSI @ (ICH) insert blank characters
CSI A (CUU) move cursor up
CSI B (CUD) move cursor down
CSI C (CUF) move cursor right
CSI D (CUB) move cursor left
CSI E (CNL) move cursor down and to column 1
CSI F (CPL) move cursor up and to column 1
CSI G (CHA) move cursor to column in current row
CSI H (CUP) move cursor to row, column
CSI J (ED) erase display
CSI K (EL) erase line
CSI L (IL) insert blank lines
CSI M (DL) delete lines
CSI P (DCH) delete characters on current line
CSI X (ECH) erase characters on current line
CSI a (HPR) move cursor right
CSI c (DA) return ESC [ ? 6 c (VT102)
CSI d (VPA) move to row (current column)
CSI e (VPR) move cursor down
CSI f (HVP) move cursor to row, column
CSI m (SGR) set graphic rendition
CSI n (DSR) device status report
CSI r (DECSTBM) set scrolling region to (top, bottom) rows
CSI ` (HPA) move cursor to column in current row
LIMITATIONS
Unknown escape sequences and control characters are ignored.
The following known control characters are ignored:
005 (ENQ) trigger answerback message
016 (SO) activate G1 charset, carriage return
017 (SI) activate G0 charset
021 (XON) resume transmission
023 (XOFF) stop transmission
The following known escape sequences are ignored:
ESC 7 (DECSC) save state
ESC 8 (DECRC) restore most recently saved state
ESC %@ (CSDFL) select default charset (ISO646/8859-1)
ESC %G (CSUTF8) select UTF-8
ESC %8 (CSUTF8) select UTF-8 (obsolete)
ESC #8 (DECALN) DEC alignment test - fill screen with E's
ESC (8 (G0DFL) G0 charset = default mapping (ISO8859-1)
ESC (0 (G0GFX) G0 charset = VT100 graphics mapping
ESC (U (G0ROM) G0 charset = null mapping (straight to ROM)
ESC (K (G0USR) G0 charset = user defined mapping
ESC )8 (G1DFL) G1 charset = default mapping (ISO8859-1)
ESC )0 (G1GFX) G1 charset = VT100 graphics mapping
ESC )U (G1ROM) G1 charset = null mapping (straight to ROM)
ESC )K (G1USR) G1 charset = user defined mapping
ESC *8 (G2DFL) G2 charset = default mapping (ISO8859-1)
ESC *0 (G2GFX) G2 charset = VT100 graphics mapping
ESC *U (G2ROM) G2 charset = null mapping (straight to ROM)
ESC *K (G2USR) G2 charset = user defined mapping
ESC +8 (G3DFL) G3 charset = default mapping (ISO8859-1)
ESC +0 (G3GFX) G3 charset = VT100 graphics mapping
ESC +U (G3ROM) G3 charset = null mapping (straight to ROM)
ESC +K (G3USR) G3 charset = user defined mapping
ESC > (DECPNM) set numeric keypad mode
ESC = (DECPAM) set application keypad mode
ESC H (HTS) set tab stop at current column
ESC N (SS2) select G2 charset for next char only
ESC O (SS3) select G3 charset for next char only
ESC P (DCS) device control string (ended by ST)
ESC X (SOS) start of string
ESC ^ (PM) privacy message (ended by ST)
ESC \ (ST) string terminator
ESC n (LS2) invoke G2 charset
ESC o (LS3) invoke G3 charset
ESC | (LS3R) invoke G3 charset as GR
ESC } (LS2R) invoke G2 charset as GR
ESC ~ (LS1R) invoke G1 charset as GR
The following known CSI (ESC [) sequences are ignored:
CSI g (TBC) clear tab stop (CSI 3 g = clear all stops)
CSI h (SM) set mode
CSI l (RM) reset mode
CSI q (DECLL) set keyboard LEDs
CSI s (CUPSV) save cursor position
CSI u (CUPRS) restore cursor position
AUTHOR
Copyright (C) 2001 Andrew Wood <andrew.wood@ivarch.com>
. Distributed under the terms of the Artistic License.
SEE ALSO
console_codes(4)