User Tools

Site Tools


create_personal_terminfo_db

Creating a Personal terminfo(1) Database

Intro:

Although most terminals today are virtual instead of physical much of their on-screen behavior is still dictated by definitions derived from 1980s era hardware. On NetBSD, the OS which the SDF cluster runs on, the various system-wide terminal definitions are stored in the /usr/share/misc/terminfo (source w/ copious comments) and /usr/share/misc/terminfo.cdb (database) files.

Displaying Terminal Info:

The current active terminal is assigned to the TERM environmental variable:

$ echo $TERM
xterm

The tput(1) command can be used to display the long description:

$ tput longname
xterm terminal emulator (X Window System)

Pass tput(1) the -T <term> option to display some other terminal's description:

$ tput -T wsvt25 longname
NetBSD wscons in 25 line DEC VT220 mode

To see the actual terminal definition use the infocmp(1) command:

$ infocmp
# Reconstructed from /usr/share/misc/terminfo.cdb
xterm|xterm terminal emulator (X Window System),
	AX, XT, am, bce, bs, km, mc5i, mir, msgr, npc, xenl,
	colors#8, cols#80, it#8, lines#24, pairs#64,
	Cr=\E]112\007, Cs=\E]12;%p1%s\007, E3=\E[3J,
        ...

where,

  • 1st line lists the referenced terminfo DB
  • 2nd line lists “<term>|<alias>|<long description>” ; alias is optional
  • subsequent lines are terminal attributes ; may be boolean, string, or inclusions

The infocmp(1) command is quite capable and can be used to compare two terminal definitions side by side; note the -a and -x options simply includes any commented out and/or non-standard attributes:

# compare wsvt25 and pcvt25 and filter results through awk(1) for better readability:
$ infocmp -ax wsvt25 pcvt25 |\
  awk -F'[:,]' -vOFS='\t' '/[,:]/{sub("[.]$","");print $1":",$2,"vs",$3;next};//'
  comparing wsvt25 to pcvt25.
    comparing booleans.
	bce:	 T	vs	F
	km:	 F	vs	T
	mc5i:	 T	vs	F
	xon:	 T	vs	F
    comparing numbers.
	colors:	 8	vs	 NULL
	pairs:	 64	vs	 NULL
        ...

Tweaking a Terminal Definition:

If the need to modify a terminal definition arises, the standard files for personal terminfo(1) definitions are ~/.terminfo (source) & ~/.terminfo.cdb (db), though the TERMINFO and TERMINFO_DIRS environmental variables can be used to designate alternate locations; see terminfo(5) for details.

As a working example, the “back color erase” (bce) attribute, known to occasionally cause display issues in certain curses-based applications, will be removed from the xterm terminal definition and stored in the personal ~/.terminfo.cdb which has presidence over the system-wide DB:

# write std xterm definition to ~/.terminfo (-x => include non-std capabilities):
$ infocmp -x xterm > ~/.terminfo 

# show presence of 'bce' attribute in std definition: 
$ grep 'bce, ' ~/.terminfo                                                                                                                                                      
	AX, XT, am, bce, bs, km, mc5i, mir, msgr, npc, xenl,

# remove the 'bce' attribute to create new definition:
$ sed -i 's/bce, //' ~/.terminfo 

# use tic(1) to compile personal DB file:              
$ tic -ax ~/.terminfo   

# show the personal terminfo source & DB file info:
$ file ~/.terminfo*
.terminfo:     ASCII text
.terminfo.cdb: NetBSD Constant Database, version 1,...

# show absence of 'bce' attribute in new xterm definition:
$ infocmp -a |head -n3
# Reconstructed from ~/.terminfo.cdb
xterm|xterm terminal emulator (X Window System),
	am, km, mc5i, mir, msgr, npc, xenl,

# Compare both definitions using infocmp(1) - only differences are displayed.
# Note 'bce' attribute is a boolean and False in new xterm definition:
$ infocmp -a -A ~/.terminfo.cdb  -B /usr/share/misc/terminfo.cdb xterm xterm                                                                                 
comparing xterm to xterm.
    comparing booleans.
	bce: F:T.
    comparing numbers.
    comparing strings.

References:

  • manpages: infocmp(1), tic(1), tput(1), terminfo(5)
  • files: /usr/share/misc/terminfo
create_personal_terminfo_db.txt · Last modified: by zilog