Hotkey program -- help needed

David Wright dwright at wheaton.UUCP
Wed Jul 11 02:34:06 AEST 1990


comp.lang.c
Keywords: tty stuff

I am trying to write a hotkey program in C that will be integrated into a menu
program on our system (Ultrix 3.0).  It should allow users to type a certain
key (e.g. ^A) inside of VI or ELM or RN.  They will then be presented with
a help menu.

So far I've tried several approaches.  I started out with an idea taken from
some code that was written for System V.  This approach basically did a fork
and an exec (Vi or ELM, etc.), with a pipe set up between the parent and the
child.  On one side of the pipe, characters were read from stdin in RAW mode,
tested for the hotkey character (which would have brought up a help menu,
and then written to the pipe and read on the other side (by VI or whatever) as
if they were coming from the stdin.  This idea involved switching back and 
forth between raw mode and an initial saved tty status, every time a character 
was read (probably because vi wouldn't like the line in Raw mode).  I am
surprised this method is supposed to have worked on System V, and there is a
lot of overhead, but it was worth a try.

I could actually get vi to run, but it was messed up, probably because it
didn't like the constant switching of the line's mode.  When I ran Elm this
way, some of Elm's escape codes got eaten.

Another method I tried was to use the approach taken in the code for the
'script' command.  Script establishes a pseudo tty line, which allows its
input (in RAW mode) to be written to a shell, which is on the pseudo tty and
can be in whatever mode is needed (say to run VI or ELM). The pseudo tty is
disassociated from the the controlling tty with an 'ioctl(TIOCNOTTY)'.
I worked on the script code for a while and got something working.  But
again there was a problem with modes. Vi was not happy (the '~'s that mark
empty lines were written diagonally across the screen) and Elm's escape codes
were being eaten.  Probably if I played around with script a little more, I
could get it to work.

There was a third method I tried, which is a compromise between the first
method and the script method.  Again forks and a pipe, but disassociating
the exec'd process (say VI) from the controlling tty.  Again I couldn't get
the proper modes (VI said something about needing an addressible cursor or an
upline capbility--which is strange, because if I shelled out of vi, which
was in line editing mode, and checked my environment, I had my TERM varible
and my TERMCAP entry).

This is just a summary of what I have tried.  I have tried lots of different
combinations, and nothing seems to get the right modes for either VI or Elm.

If anyone has done something like a hotkey before or knows what to do, I would
greatly appreciate any help.

Thanks.

David Wright
dwright at wheaton.uucp



More information about the Comp.unix.wizards mailing list