[comp.sys.dec] Cursor key input in curses ?

doelz@urz.unibas.ch (04/20/91)

Problem: 
How do you input cursor keys in curses ? 

Background:
I want to show a menu on the screen which is similar to the one you get from 
SMG$ on VAX/VMS. The curses package available in C gives the problem 
that the cursor key is read either as terminator or as a sequence of three 
characters (e.g.,  <ESC> [ A ) in vt100 emulation instead of a cursor key. 

Please: 
I would be grateful if someone in netland could explain me what goes wrong on
the vt100 emulation side or even get me a piece of code which reads in a cursor 
key correctly. 

Regards 
Reinhard                                   

+-----------------------------------------------------------------------------+
|Dr. Reinhard Doelz  | X.400: S=doelz,OU=urz,O=unibas,P=switch,A=arcom,C=ch   |
|  Universitaets-    | RFC  : doelz@urz.unibas.ch                             |
|  rechenzentrum     | X.25 : psi%022846211142::embnet                        |
| Klingelbergstr.70  | Tel. : +41 61 267 2076    +----------------------------+
|  CH 4056 Basel     | Fax. : +41 61 261 6760    |    S W I T Z E R L A N D
+------------------------------------------------+     

kcwellsch@watdragon.waterloo.edu (Ken Wellsch) (04/21/91)

> Problem: 
> How do you input cursor keys in curses ? 
>
> Please: 
> I would be grateful if someone in netland could explain me what goes wrong
> on the vt100 emulation side or even get me a piece of code which reads
> in a cursor key correctly.

I'll put my two-bits in on this one.  Unlike VMS which I believe has a
strong dislike for any terminal that is not DEC (e.g. VT100 etc.), a
package like curses has the horrid task of trying to understand numerous
terminal types (thousands of old and new terminals - actually "termcap"
describes them, while curses tries to provide a windowing environment
for a regular tty).

Now if you receive the three characters that a VT100 arrow key sends, or
if your application (say "emacs") understands that set of key strokes to
mean something else (unlikely but possible), how do you decide which it
is?  The three characters or "an arrow key was hit?"

The few screen oriented programs that I have studied that attempt to handle
this use the "select" system call as I recall to do very short waits on
input (say 50-100 mSec) and if another character is received that continues
an arrow key-stroke then we continue to guess it is an arrow key and
not separate key strokes.  If there is sufficent lag, I think one tended
to assume it was not an arrow key.

I took a very quick look at 4.3BSD's curses source and didn't see anything
attempting this sort of (admittedly painful) approach.

mdchaney@bronze.ucs.indiana.edu (M Darrin Chaney) (04/23/91)

In article <1991Apr21.015251.6148@watdragon.waterloo.edu> kcwellsch@watdragon.waterloo.edu (Ken Wellsch) writes:
>I'll put my two-bits in on this one.  Unlike VMS which I believe has a
>strong dislike for any terminal that is not DEC (e.g. VT100 etc.), a
>package like curses has the horrid task of trying to understand numerous
>terminal types (thousands of old and new terminals - actually "termcap"
>describes them, while curses tries to provide a windowing environment
>for a regular tty).

If you'd check into SMG, you'd find that it also supports any terminal
that you're willing to make an entry for.  DEC may have a dislike for
old terminals, but let's face it, the 70's are gone.  Just about any
terminal worth its salt knows at least the ANSI sequences.

SMG is a superset of Curses, and has many more horrid tasks...

	Darrin
-- 

mdchaney@iubacs
mdchaney@bronze.ucs.indiana.edu
mdchaney@rose.ucs.indiana.edu

peirce@gumby.cc.wmich.edu (Leonard Peirce) (04/24/91)

In article <1991Apr20.160134.1514@urz.unibas.ch> doelz@urz.unibas.ch writes:
>How do you input cursor keys in curses ? 
>
>Background:
>I want to show a menu on the screen which is similar to the one you get from 
>SMG$ on VAX/VMS. The curses package available in C gives the problem 
>that the cursor key is read either as terminator or as a sequence of three 
>characters (e.g.,  <ESC> [ A ) in vt100 emulation instead of a cursor key. 

This was fixed in 4.0 although not completely.  I complained to DEC on
numerous occasions when I was running 3.x and they finally sent me a patch
but it only fixed the cursor keys.  Keys like Prev Screen, Next Screen,
Find, etc., were still broken.  I was hoping everything would be fixed in
4.x.  Sigh.....

Sometime ago, someone posted here what the problem was.  It was something
like a parameter being passed to a subroutine incorrectly.  I looked for it
in what seems like an endless archive of stuff that I save but I couldn't
find it.

I would SPR this myself but I'm too busy trying to fix LAT printing.  Maybe
sometime this week or early next week I'll have something to post about it.
Grrr.....

--
Leonard Peirce                  Internet:  peirce@gumby.cc.wmich.edu
Western Michigan University                peirce@gw.wmich.edu
Academic Computing Services     UUCP:      ...!uunet!sharkey!wmichgw!peirce
Kalamazoo, MI  49008            Phone:     (616) 387-5469

"Answer that, it may be the phone." -- Anthony Wachs, "Tony In RH20 Land"

vancleef@iastate.edu (Van Cleef Henry H) (04/25/91)

In article <1991Apr24.140134.26133@gumby.cc.wmich.edu> peirce@gumby.cc.wmich.edu (Leonard Peirce) writes: 
>
>This was fixed in 4.0 although not completely.  I complained to DEC on
>numerous occasions when I was running 3.x and they finally sent me a patch
>but it only fixed the cursor keys.  Keys like Prev Screen, Next Screen,
>Find, etc., were still broken.  I was hoping everything would be fixed in
>4.x.  Sigh.....
>
>Sometime ago, someone posted here what the problem was.  It was something
>like a parameter being passed to a subroutine incorrectly.  I looked for it
>in what seems like an endless archive of stuff that I save but I couldn't
>find it.
>
>I would SPR this myself but I'm too busy trying to fix LAT printing.  Maybe
>sometime this week or early next week I'll have something to post about it.
>Grrr.....
>
>--
>Leonard Peirce                  Internet:  peirce@gumby.cc.wmich.edu
>Western Michigan University                peirce@gw.wmich.edu
>Academic Computing Services     UUCP:      ...!uunet!sharkey!wmichgw!peirce
>Kalamazoo, MI  49008            Phone:     (616) 387-5469
>
>"Answer that, it may be the phone." -- Anthony Wachs, "Tony In RH20 Land"

For those who don't know about it, Aspen Scientific in Colorado has an
excellent terminfo curses package for MS-DOS, OS/2, and VMS.  I have
used it to port Curses programs from Unix to these platforms.  If you
are doing serious work with Curses, I'd take a look at Aspen.  Don't have
their address here, somewhere in Denver area like Ft. Collins as I recall.
--