Term::Cap(3pm)
π Term::Cap
okay bestie, welcome to Term::Cap(3pm) β the Perl module that's literally your VIP pass to the termcap database π she's giving low-level, she's giving old-school, and she absolutely ate.
β¨ NAME β¨
Term::Cap β the Perl termcap interface, no cap π
πΈ SYNOPSIS πΈ
require Term::Cap;
$terminal = Term::Cap->Tgetent({ TERM => undef, OSPEED => $ospeed });
$terminal->Trequire(qw/ce ku kd/);
$terminal->Tgoto('cm', $col, $row, $FH);
$terminal->Tputs('dl', $count, $FH);
$terminal->Tpad($string, $count, $FH);
π DESCRIPTION π
These are the low-level girlies β functions that pull capabilities out of a terminal capability (termcap) database and then actually use them. π§
If you want the deep lore on terminal capabilities themselves, check the termcap manpage on most Unix-like systems. iykyk.
π¦ METHODS
Since your girl cares about performance: the output strings for Tputs get cached for counts of 1. Tgoto and Tpad? Nope, they do not cache, they're free spirits. Also know that "$self->{_xx}" is the raw termcap data and "$self->{xx}" is the cached version:
print $terminal->Tpad($self->{_xx}, 1);
Tgoto, Tputs, and Tpad all return the string, and they'll also output the string to $FH if you specified one. double duty, iconic π
β Tgetent
Returns a blessed object reference that you can then use to yeet control strings to the terminal via Tputs and Tgoto.
It extracts the entry for the specified terminal type TERM (which defaults to the environment variable TERM) out of the database.
So here's the search saga, bestie, pay attention:
- It looks in the environment for a
TERMCAPvariable. - If found, and the value does not begin with a slash, and the terminal type name is the same as the environment string
TERM, then theTERMCAPstring is used instead of reading a termcap file. slay, shortcut π - If it does begin with a slash, the string is used as a path name of the termcap file to search.
- If
TERMCAPdoes not begin with a slash and the name is different fromTERM,Tgetentsearches the files$HOME/.termcap,/etc/termcap, and/usr/share/misc/termcap, in that order β unless the environment variableTERMPATHexists, in which caseTERMPATHspecifies a list of file pathnames (separated by spaces or colons) to be searched instead. - Whenever multiple files are searched and a
tcfield occurs in the requested entry, the entry it names must be found in the same file or one of the succeeding files. no skipping ahead π« - If there's a
":tc=...:"in theTERMCAPenvironment variable string, it will continue the search in the files as described above.
The extracted termcap entry lives on the object at "$self->{TERMCAP}". π«Ά
It takes a hash reference as an argument, with two optional keys:
OSPEEDβ the terminal output bit rate (often mistakenly called the baud rate) for this terminal. If you don't set it, a warning gets generated and it defaults to9600.OSPEEDcan be given as either a POSIX termios/SYSV termio speed (where9600equals9600) or an old DSD-style speed (where13equals9600). cursed but valid πTERMβ the terminal type whose termcap entry will be used. If not supplied it defaults to$ENV{TERM}; if that isn't set either,Tgetentwillcroak. she's dramatic like that π
It calls "croak" on failure. periodt.
π Tpad
Outputs a literal string with the appropriate padding for your current terminal.
It takes three arguments:
$stringβ the literal string to be output. If it starts with a number and an optional'*', then the padding gets increased by an amount relative to this number; and if the'*'is present, that amount is multiplied by$cnt. This part of$stringis removed before output.$cntβ used to modify the padding applied to the string, as described above.$FHβ an optional filehandle (orIO::Handle) that output gets printed to.
The padded $string is returned. πΈ
π Tputs
Outputs the string for the given capability, padded as appropriate, with no parameter substitution.
Three arguments, let's go:
$capβ the capability whose string is to be output.$cntβ a count passed toTpadto modify the padding applied to the output string. If$cntis zero or one, then the resulting string gets cached. β¨$FHβ an optional filehandle (orIO::Handle) that output gets printed to.
The appropriate string for the capability is returned.
π₯ Tgoto
Tgoto decodes a cursor addressing string using the parameters you give it.
Four arguments, bestie:
$capβ the name of the capability to be output.$colβ the first value substituted into the output string (usually the column in a cursor addressing capability).$rowβ the second value substituted into the output string (usually the row in cursor addressing capabilities).$FHβ an optional filehandle (orIO::Handle) that the output string gets printed to.
Substitutions are made with $col and $row in the output string using these sprintf() line formats:
%% output `%'
%d output value as in printf %d
%2 output value as in printf %2d
%3 output value as in printf %3d
%. output value as in printf %c
%+x add x to value, then do %.
%>xy if value > x then add y, no output
%r reverse order of two parameters, no output
%i increment by one, no output
%B BCD (16*(value/10)) + (value%10), no output
%n exclusive-or all parameters with 0140 (Datamedia 2500)
%D Reverse coding (value - 2*(value%16)), no output (Delta Data)
The output string will be returned. π
π Trequire
Takes a list of capabilities as an argument and will croak if one of them isn't found. she checks receipts, always π
β EXAMPLES β
use Term::Cap;
# Get terminal output speed
require POSIX;
my $termios = POSIX::Termios->new;
$termios->getattr;
my $ospeed = $termios->getospeed;
# Old-style ioctl code to get ospeed:
# require 'ioctl.pl';
# ioctl(TTY,$TIOCGETP,$sgtty);
# ($ispeed,$ospeed) = unpack('cc',$sgtty);
# allocate and initialize a terminal structure
my $terminal = Term::Cap->Tgetent({ TERM => undef, OSPEED => $ospeed });
# require certain capabilities to be available
$terminal->Trequire(qw/ce ku kd/);
# Output Routines, if $FH is undefined these just return the string
# Tgoto does the % expansion stuff with the given args
$terminal->Tgoto('cm', $col, $row, $FH);
# Tputs doesn't do any % expansion.
$terminal->Tputs('dl', $count = 1, $FH);
π COPYRIGHT AND LICENSE π
Copyright 1995-2015 (c) perl5 porters.
This software is free software and can be modified and distributed under the same terms as Perl itself. π«Ά
Please see the file README in the Perl source distribution for the details of the Perl license.
π AUTHOR π
This module is part of the core Perl distribution and is also maintained for CPAN by Jonathan Stowe <jns@gellyfish.co.uk>.
The code is hosted on Github: https://github.com/jonathanstowe/Term-Cap β please feel free to fork, submit patches etc, etc there. go off π
πΈ SEE ALSO πΈ
and that's the whole page, bestie β¨ this one shipped with perl v5.42.3 and got stamped 2026-11-03 β she's dated, she's official, she's iconic, mwah ππ
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms