1Term::Cap(3pm)         Perl Programmers Reference Guide         Term::Cap(3pm)
2
3
4

NAME

6       Term::Cap - Perl termcap interface
7

SYNOPSIS

9           require Term::Cap;
10           $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
11           $terminal->Trequire(qw/ce ku kd/);
12           $terminal->Tgoto('cm', $col, $row, $FH);
13           $terminal->Tputs('dl', $count, $FH);
14           $terminal->Tpad($string, $count, $FH);
15

DESCRIPTION

17       These are low-level functions to extract and use capabilities from a
18       terminal capability (termcap) database.
19
20       More information on the terminal capabilities will be found in the
21       termcap manpage on most Unix-like systems.
22
23       METHODS
24
25           The output strings for Tputs are cached for counts of 1 for perfor‐
26           mance.  Tgoto and Tpad do not cache.  "$self->{_xx}" is the raw
27           termcap data and "$self->{xx}" is the cached version.
28
29               print $terminal->Tpad($self->{_xx}, 1);
30
31           Tgoto, Tputs, and Tpad return the string and will also output the
32           string to $FH if specified.
33
34       Tgetent
35           Returns a blessed object reference which the user can then use to
36           send the control strings to the terminal using Tputs and Tgoto.
37
38           The function extracts the entry of the specified terminal type TERM
39           (defaults to the environment variable TERM) from the database.
40
41           It will look in the environment for a TERMCAP variable.  If found,
42           and the value does not begin with a slash, and the terminal type
43           name is the same as the environment string TERM, the TERMCAP string
44           is used instead of reading a termcap file.  If it does begin with a
45           slash, the string is used as a path name of the termcap file to
46           search.  If TERMCAP does not begin with a slash and name is differ‐
47           ent from TERM, Tgetent searches the files $HOME/.termcap,
48           /etc/termcap, and /usr/share/misc/termcap, in that order, unless
49           the environment variable TERMPATH exists, in which case it speci‐
50           fies a list of file pathnames (separated by spaces or colons) to be
51           searched instead.  Whenever multiple files are searched and a tc
52           field occurs in the requested entry, the entry it names must be
53           found in the same file or one of the succeeding files.  If there is
54           a ":tc=...:" in the TERMCAP environment variable string it will
55           continue the search in the files as above.
56
57           The extracted termcap entry is available in the object as
58           "$self->{TERMCAP}".
59
60           It takes a hash reference as an argument with two optional keys:
61
62           OSPEED
63             The terminal output bit rate (often mistakenly called the baud
64             rate) for this terminal - if not set a warning will be generated
65             and it will be defaulted to 9600.  OSPEED can be be specified as
66             either a POSIX termios/SYSV termio speeds (where 9600 equals
67             9600) or an old DSD-style speed ( where 13 equals 9600).
68
69           TERM
70             The terminal type whose termcap entry will be used - if not sup‐
71             plied it will default to $ENV{TERM}: if that is not set then Tge‐
72             tent will croak.
73
74           It calls "croak" on failure.
75
76       Tpad
77           Outputs a literal string with appropriate padding for the current
78           terminal.
79
80           It takes three arguments:
81
82           $string
83             The literal string to be output.  If it starts with a number and
84             an optional '*' then the padding will be increased by an amount
85             relative to this number, if the '*' is present then this amount
86             will me multiplied by $cnt.  This part of $string is removed
87             before output/
88
89           $cnt
90             Will be used to modify the padding applied to string as described
91             above.
92
93           $FH
94             An optional filehandle (or IO::Handle ) that output will be
95             printed to.
96
97           The padded $string is returned.
98
99       Tputs
100           Output the string for the given capability padded as appropriate
101           without any parameter substitution.
102
103           It takes three arguments:
104
105           $cap
106             The capability whose string is to be output.
107
108           $cnt
109             A count passed to Tpad to modify the padding applied to the out‐
110             put string.  If $cnt is zero or one then the resulting string
111             will be cached.
112
113           $FH
114             An optional filehandle (or IO::Handle ) that output will be
115             printed to.
116
117           The appropriate string for the capability will be returned.
118
119       Tgoto
120           Tgoto decodes a cursor addressing string with the given parameters.
121
122           There are four arguments:
123
124           $cap
125             The name of the capability to be output.
126
127           $col
128             The first value to be substituted in the output string ( usually
129             the column in a cursor addressing capability )
130
131           $row
132             The second value to be substituted in the output string (usually
133             the row in cursor addressing capabilities)
134
135           $FH
136             An optional filehandle (or IO::Handle ) to which the output
137             string will be printed.
138
139           Substitutions are made with $col and $row in the output string with
140           the following sprintf() line formats:
141
142            %%   output `%'
143            %d   output value as in printf %d
144            %2   output value as in printf %2d
145            %3   output value as in printf %3d
146            %.   output value as in printf %c
147            %+x  add x to value, then do %.
148
149            %>xy if value > x then add y, no output
150            %r   reverse order of two parameters, no output
151            %i   increment by one, no output
152            %B   BCD (16*(value/10)) + (value%10), no output
153
154            %n   exclusive-or all parameters with 0140 (Datamedia 2500)
155            %D   Reverse coding (value - 2*(value%16)), no output (Delta Data)
156
157           The output string will be returned.
158
159       Trequire
160           Takes a list of capabilities as an argument and will croak if one
161           is not found.
162

EXAMPLES

164           use Term::Cap;
165
166           # Get terminal output speed
167           require POSIX;
168           my $termios = new POSIX::Termios;
169           $termios->getattr;
170           my $ospeed = $termios->getospeed;
171
172           # Old-style ioctl code to get ospeed:
173           #     require 'ioctl.pl';
174           #     ioctl(TTY,$TIOCGETP,$sgtty);
175           #     ($ispeed,$ospeed) = unpack('cc',$sgtty);
176
177           # allocate and initialize a terminal structure
178           $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
179
180           # require certain capabilities to be available
181           $terminal->Trequire(qw/ce ku kd/);
182
183           # Output Routines, if $FH is undefined these just return the string
184
185           # Tgoto does the % expansion stuff with the given args
186           $terminal->Tgoto('cm', $col, $row, $FH);
187
188           # Tputs doesn't do any % expansion.
189           $terminal->Tputs('dl', $count = 1, $FH);
190
192       Please see the README file in distribution.
193

AUTHOR

195       This module is part of the core Perl distribution and is also main‐
196       tained for CPAN by Jonathan Stowe <jns@gellyfish.com>.
197

SEE ALSO

199       termcap(5)
200
201
202
203perl v5.8.8                       2001-09-21                    Term::Cap(3pm)
Impressum