[comp.unix.questions] How to mimic the terminal driver?

vishwana@umvlsi.ECS.UMASS.EDU (Chidambaram Vishwanath) (11/30/88)

     I have taken upon myself the following task, viz.,: I want to add 
an extra feature to the C-shell whereby I can recall earlier commands
by pressing an arrow-key.  I thought first of using 'stty' to
reconfigure the arrow key to be an interrupt key, and then program the
shell to trap the interrupt and process it appropriately. But very 
quickly I discovered that the command-line shell cannot be interrupted.

	So I thought of another possible approach. A program would 
interpose between a child c-shell and the terminal. This program would
take characters from the terminal and deliver them to the shell.(Both
my program and the shell are running in the foreground, connected by a
pipe.)  However here is where I ran into another problem.  How to 
return the end_of_file condition to the reading shell?  For instance,
the 'command-completion' facility in the C-shell depends upon the user
hitting '^D' after entering some text.  My program can detect the eof,
but how is it to communicate it to the shell to which it is connected?

	I will be grateful for any pointers towards solving this
problem, or comments as to the feasibility of the whole approach alto-
gether.

			Thank you,
					Vishwanath,
					University of Mass. at Amherst.
e-mail: vishwana@umaecs (BITNET)
        vishwana@ecs.umass.edu (CSNET)

dieter@titan.nmt.edu (The Demented Teddy Bear) (11/30/88)

In article <35@umvlsi.ECS.UMASS.EDU>, vishwana@umvlsi (Chidambaram Vishwanath) writes:
> 
>      I have taken upon myself the following task, viz.,: I want to add 
> an extra feature to the C-shell whereby I can recall earlier commands
> by pressing an arrow-key.

By far the easiest solution to this problem is to use "ile", which was
posted to comp.unix.wizards on July 7, 1988 by bpendlet@esunix.uucp.
(Bob Pendleton, message id 907@esunix.uucp, to be exact).  It fits
between the user and his program by grabbing a pty and looking at
everything that goes by.

There are three problems with this package that I'm aware of.

1) Your version of unix must understand the concept of pty.  This seems
   to be fairly common these days, so it isn't too much of a problem.

2) It grabs a pty, but doesn't update /etc/utmp, which upsets "talk" and
   other programs that do a getlogin ().  This is pretty easy to fix (I
   just finished doing that about 4 hours ago, you see).

3) To keep things from getting real confused, the tty never echoes (i.e.,
   the child's end doesn't echo), but the pty does.  Therefore, there's
   no way for ile to know that the child would like echoing turned off.
   Translation:  passwords echo.  I haven't figured out a nice way around
   this yet.

4) There's no clear concept of "current directory".  Since this would
   require something of a Know-What-I-Mean function, there's not much
   that can be done about it.

Some advantages:

1) Ile notices when the child puts the tty into raw mode, and gets out of
   the way.  Things like Emacs still work.

2) You now have an Emacs-like user interface.  Things like ^A, ^E, ^T
   ESC-u, etc, all work.  You can change the default key bindings to
   whatever you prefer.  Characters insert by default.

3) File name completion exists, but only on absolute paths (start with
   a / or ~).  I haven't figured out how to get an escape through to the
   shell for its completion yet, assuming it's possible.

4) *All* line-oriented programs suddenly have history, with a nice line
   editing capability.  Ile maintains its own history list (accessed via
   ^P and ^N by default), and doesn't distinguish between what subprocess
   is reading from the pty.  It's real convenient being able to pop up
   the history list and grab the command line you typed at the wrong program
   and give it to the right program.  You don't need one of those
   "...relentlessly interactive, icon-based, rodent-infested, dumb-user-
   friendly, smart-user-crippling systems..."[*] any more.

I have the original message (as you probably guessed from the exactness
in identification given at the top).  The diffs for diddling utmp nicely
(cleans up after itself and such) are fairly small, and on their way to
the original author.

Please note that I will not be at this email address after Dec 12, so
either get any requests in to me quickly, or send a note off to Mr.
Pendleton.

[*] Thanks to Mike Van Pelt for that description.

Dieter Muller
-- 
Welcome to the island.  You are number six.
dieter%nmt@relay.cs.net
dieter@jupiter.nmt.edu

gwyn@smoke.BRL.MIL (Doug Gwyn ) (12/01/88)

In article <35@umvlsi.ECS.UMASS.EDU> vishwana@umvlsi.ECS.UMASS.EDU (Chidambaram Vishwanath) writes:
>     I have taken upon myself the following task, viz.,: I want to add 
>an extra feature to the C-shell whereby I can recall earlier commands
>by pressing an arrow-key.  [etc.]

Why reinvent the wheel?  The so-called "Tenex Cshell" already has similar
support built in.  I think it may even have become the standard 4.3BSD
Cshell.  You can also get this in the Korn shell and the BRL Bourne shell.
A terminal editing wrapper process was posted to one of the newsgroups
only a few months ago, if you want to use the separate-process approach.