itlib.icn: Procedures for termlib-type tools

link itlib
September 2, 2010; Richard L. Goerwitz
Contributor: Clinton L. Jeffery
Requires: UNIX, co-expressions
See also: iscreen.icn, iolib.icn, itlibdos.icn
This file is in the public domain.

The following library represents a series of rough functional
equivalents to the standard UNIX low-level termcap routines.  They
are not meant as exact termlib clones.  Nor are they enhanced to
take care of magic cookie terminals, terminals that use \D in their
termcap entries, or, in short, anything I felt would not affect my
normal, day-to-day work with ANSI and vt100 terminals.  There are
some machines with incomplete or skewed implementations of stty for
which itlib will not work.  See the BUGS section below for work-
arounds.
____________________________________________________________

setname(term)
     Use only if you wish to initialize itermlib for a terminal
other than what your current environment specifies.  "Term" is the
name of the termcap entry to use.  Normally this initialization is
done automatically, and need not concern the user.

getval(id)
     Works something like tgetnum, tgetflag, and tgetstr.  In the
spirit of Icon, all three have been collapsed into one routine.
Integer valued caps are returned as integers, strings as strings,
and flags as records (if a flag is set, then type(flag) will return
"true").  Absence of a given capability is signalled by procedure
failure.

igoto(cm,destcol,destline) - NB:  default 1 offset (*not* zero)!
     Analogous to tgoto.  "Cm" is the cursor movement command for
the current terminal, as obtained via getval("cm").  Igoto()
returns a string which, when output via iputs, will cause the
cursor to move to column "destcol" and line "destline."  Column and
line are always calculated using a *one* offset.  This is far more
Iconish than the normal zero offset used by tgoto.  If you want to
go to the first square on your screen, then include in your program
"iputs(igoto(getval("cm"),1,1))."

iputs(cp,affcnt)
     Equivalent to tputs.  "Cp" is a string obtained via getval(),
or, in the case of "cm," via igoto(getval("cm"),x,y).  Affcnt is a
count of affected lines.  It is only relevant for terminals which
specify proportional (starred) delays in their termcap entries.
____________________________________________________________

BUGS:  I have not tested these routines much on terminals that
require padding.  These routines WILL NOT WORK if your machine's
stty command has no -g option (tisk, tisk).  This includes 1.0 NeXT
workstations, and some others that I haven't had time to pinpoint.
If you are on a BSD box, try typing "sh -c 'stty -g | more'" it may
be that your stty command is too clever (read stupid) to write its
output to a pipe.  The current workaround is to replace every in-
stance of /bin/stty with /usr/5bin/stty (or whatever your system
calls the System V stty command) in this file.  If you have no SysV
stty command online, try replacing "stty -g 2>&1" below with, say,
"stty -g 2>&1 1> /dev/tty."  If you are using mainly modern ter-
minals that don't need padding, consider using iolib.icn instead of
itlib.icn.

Source code | Program Library Page | Icon Home Page