Alan Curry said:
It's possible I'm not using the right library for what I want to, which is,
IMO, extremely basic input and output for a non-graphic display mode, that
is (in a small way) cross-platform. That is:
o Being able to write text at (row, column) on a screen or console window,
preferably in a choice of primary colours. (Both sets of curses seem just
about capable of that)
Not if the display is monochrome. Now I know you know this, but the
point is a general one. A library like curses hides this form you.
Some displays allow fine-grained control of the brightness of individual
characters and soon some 3D display may well allow a z-position. When a
feature becomes common place, libraries like ncurses will offer support
for them, but since the purpose of ncurses is portability it is
inherently conservative about such things.
o Being able to know what keys have been pressed on my keyboard, including
the various shifts that all computer keyboards have had for decades. I don't
consider Ctrl+Home to be that esoteric.
It may not be esoteric, but it is not universal. If you want a program
to work using common terminal types you have to accept that Ctrl+Home
can't be used.
There are ways to get round this:
(a) Use your own X window. XLib lets you know a huge amount about what
keys are being pressed and exactly when. My editor, being X aware, lets
me bind Ctrl+Alt+Super+Home (to pick an extreme example) but when I run
the editor in a terminal emulation I have to accept that this won't work
because the terminal being emulated has no way to say "Ctrl+Alt+Super+
Home was pressed and released".
(b) Go a little bit beyond what ncurses gives you and accept a loss of
flexibility. You can write a small function to read and return and
extended set of key combinations but you must then tell your users that
the software needs to run in, say, an xterm window. (I choose xterm
because it generate unique escape sequences for all sorts of
combinations like Ctrl+Home, Shift+Ctrl+Home and so on.)
(What key combo do *you* use to get
to the beginning of a file? I bet it involves a shift, ctrl or alt
key!)
(Home three times: the first goes to start of line, the second to the top
of the page and the third to start of the file. Multi key presses like
this are so fast that it's probably quicker the Ctrl+Home.)
o And being able to do so without the intermediate library taking over my
machine and/or my program (like SDL, which disables stdout and stderr!)
Imagine a computer without a network attached, but with a keyboard and basic
character display. You would surely expect those peripherals to work,
without having half their capabilities unavailable because the protocols for
controlling them via a network can't accommodate them.
I'd expect them to work (and of course they do) but you can't insist
that the work the way you want them to or that you are used to. My hard
drive works, but user programs can only access it via an very complex
and high-level abstraction provided by the OS. You are kicking against
the abstraction that *nix systems use for non-graphical terminals. All
you can do is take a deep breath and move on.
It seems that with Unix, I have to pretend that even the simplest peripheral
I want to access is at the end of a link, via an interface not updated since
the 1970s!
Obviously it has been updated, but the model is from the 1970s. It
works surprisingly well and has enough advantages that it's not going to
go away anytime soon. It's not uncommon to see old terminals still
plugged in to servers for monitoring purposes and so on.
It wouldn't be hard to provide a general method to do what you want.
All that would be need is some patches to a good terminal emulator like
xterm so that it reports (as escape sequences) raw key presses and
releases. An extended curses library could then provide access to this
virtual hardware at all sorts of levels, from actual events like "left
control down" to "Ctrl+Home pressed and released".
But I suspect this would not take off because the benefits are small
compared to work required, and programs that have any sort of
portability limitation can be viewed with suspicion. For example, with
no patching at all, you could bundle your editor with xterm (because it
does report Ctrl+Home) but the fact that it won't run in my preferred
terminal program would put me off.