dwright@wheaton.UUCP (David Wright) (07/10/90)
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@wheaton.uucp
douglas@dekalb.UUCP (Douglas B. Jones) (07/17/90)
In article <2101@wheaton.UUCP> dwright@wheaton.UUCP (David Wright) writes: >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. [Description of 3 methods omitted] >David Wright >dwright@wheaton.uucp Under BRL 4.2 there was a "hot key" (default ^T) that would print the current load averages up. I believe you could change the hot key to what ever character you wanted. If memory serves correctly, this was in the tty driver. This being the case, then you could put this in your tty driver. When ever the hot key is hit, then a routine could be called and your system wide menu program could be executed. This is a crude outline and might require a lot of work. For one, once you update the tty structure (header file) with the new element, *.hotkey, you then have to recompile everything that deals with that structure. This means kernal, library, system utilities, and local program recomps. I'm not sure if the BRL load average hot key could be turned off or not. If not, then it would be nice to set that element to a "null" value that would say this action is turned off. If memory serves correctly, the hot key would even work in raw mode. I think I am remembering wrong. Some other method might be better considering that DEC does not guarentee that the sources they send you (if you get them) will actually rebuild the current binary you have. So, buyer be ware. Cheers, Douglas -- Doulas B. Jones douglas@dekalb Academic Computer Center or gatech!dekalb!douglas DeKalb College 555 N. Indian Creek Drive/Clarkston, Ga. 30021 (404) 299-4233
brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (07/18/90)
In article <1018@dekalb.UUCP> douglas@dekalb.UUCP (Douglas B. Jones) writes: > Under BRL 4.2 there was a "hot key" (default ^T) that would print the > current load averages up. The hot key found its way into one of the BSD 4.3 variants here. > I believe you could change the hot key to > what ever character you wanted. Yes. TIOCGAUXC and TIOCSAUXC retrieve and set struct auxchars, which specifies the key and the kernel values to print. > This being the case, then you could put this in your > tty driver. Pseudo-terminals solve the problem with much less work, when they are available. ---Dan