Subject: NetBSD termcap vs. Xterm vs. libcurses and/or ncurses
To: Dave <dgriffi@cs.csubak.edu>
From: Greg A. Woods <woods@weird.com>
List: tech-userlevel
Date: 03/23/2004 19:23:03
[ On Monday, March 22, 2004 at 12:19:58 (-0800), Dave wrote: ]
> Subject: Re: ncurses vs. BSD curses
>
> 1) It seems that it's up to the curses library to decide if a program may
> or may not use color. For example, if you use compile Frotz to use
> ncurses on a NetBSD machine, it won't let you use color on an xterm.
> Why? Xterm on NetBSD uses termcap, and for some funny reason ncurses
> doesn't want to play nice with termcap.
That makes no sense to me at all.
Let's go back over the basics, though of course you may know some or all
of this:
Xterm doesn't "use" termcap, or curses for that matter. Xterm
implements a terminal emulator so that X11 users can pretend they still
use an old fashioned physical terminal.
Termcap (and terminfo) are different styles of defining how a terminal
should be driven (and what character sequences to expect from certain
keys).
Both NetBSD's libcurses and the ncurses library use these terminal
capabilities definitions to make the terminal (or terminal emulator)
display output in the right way (i.e. as consistently as possible across
a variety of terminal types) without requiring an application to
understand how to drive each possible type of terminal and how to
interpret certain character sequences received from the terminal (since
of course not all terminals or terminal emulators work the same way, and
even different versions of a given type of terminal or emulator may
behave differently).
NetBSD's libcurses uses the termcap style of terminal descriptions.
The ncurses library can use either termcap or terminfo terminal
descriptions.
You don't necessarily want to use the termcap description of an Xterm
emulator supplied by NetBSD with ncurses (and perhaps not even with
libcurses either, though it that depends on _exactly_ which version of
Xterm you're actually using).
In fact you shouldn't even use the ncurses terminfo description of an
Xterm emulator with ncurses.
You _should_ use the termcap or terminfo description of Xterm that's
supplied with the version of Xterm you're using at the moment.
I.e. if you don't use the exact description of the actual terminal or
terminal emulator you're using at any given moment then you can't expect
any application using any libcurses or ncurses library to make the
terminal display things correctly (or understand function key
sequences).
Of course there are other issues to do with how your particular version
of libcurses or ncurses interprets any given terminal description, so
there often has to be some correspondence between the terminal
descriptions and the curses library in use.
E.g. if the curses library doesn't support colour then you don't get any
benefit from using a terminal description that specifies how to set the
colours on the screen. However if the curses library does support use
of colour, but your terminal description doesn't tell the library how to
set the colours on your screen then the application won't appear in
colour no matter how hard it tries.
Remember what matters is the actual terminal or emulator the user is
interacting with -- if you use Xterm on a Sun workstation to login to a
NetBSD box and run an ncurses-using application using the NetBSD termcap
definition then you can't expect the display to work exaclty as if you
compiled and ran that same application on the Sun and use the Solaris
terminfo description of the local Xterm. In the good old days with
physical terminals that all ran the same firmware if they had the same
model number then it was easy for OS vendors to distribute their own
termcap or terminfo descriptions of common terminals that worked with
their own curses libraries and all was well. However with emulators
that actually behave differently between different versions (even though
they're supposed to be emulating specific physical terminal models),
it's a lot harder for the OS vendor to keep their own terminal
description databases up to date with all the exact bug-for-bug and
feature-for-feature details of each emulator version, though hopefully
the distributed descriptions actually match any emulator distributed
with the OS. For example if you compare the NetBSD termcap description
of "xterm" with the termcap description supplied with the latest Xterm
release you'll find quite a large number of differences, some quite
important. You'll also find a number of variants of the descriptions
have been supplied with the Xterm source too. It can all get very
confusing very quickly, especially if a user has to use different
descriptions (e.g. via different TERM settings) for different
applications. As I understand it the description of "xterm" distributed
with NetBSD's termcap file is intended to be generic enough to work with
as many Xterm variants as possible, which by definition means that it
can't support all the features of any one specific Xterm release.
"The nice thing about standards is there are so many to choose from."
Now if only I could get the Xterm I'm using to understand <Ctrl-PgUp>
regardless of which X11 display and keyboard I'm using. Sigh. I guess
I'll have to fiddle with Xkeycaps for that....
--
Greg A. Woods
+1 416 218-0098 VE3TCP RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com> Secrets of the Weird <woods@weird.com>