[comp.mail.mush] macros that end in tilde

pwolfe@kailand.kai.COM (Patrick Wolfe) (07/28/89)

There appears to be a bug in Mush 6.5.6 handling macros activated by codes that
end in tilde's.  I'm trying to use the "map" command in line mode to define
commands to be executed when I press my VT220 compatible terminal's function
keys.  These function keys all end with a tilde.

The command in my .mushrc is:
        map '\E[20~' "echo f9 was pressed\n"

When I press function key "f9" after a prompt, instead of displaying the
message, mush usually pauses for a second, then displays '^E[20~', exactly what
the function key sent, on the command line, as though it didn't recognize the
macro.  I say usually, because once in a while it works correctly, but about
90% of the time it doesn't.  I can't isolate any conditions that cause it to
fail repeatedly.

If I manually type the key sequence in, it executes the macro correctly, and
displays my message.  If I press the function key and then any other key
immediately (such as the space bar), the macro is expanded perfectly.  If I map
the code leaving off the tilde, it works every time, except for the unfortunate
side effect of having a tilde placed at the beginning of the next command
line.

Can someone please help me find a way to get mush to reliably handle my
function key macros?


        Patrick Wolfe   (pat@kai.com, kailand!pat)
        System Manager, Kuck & Associates, Inc.


-- 

        Patrick Wolfe   (pat@kai.com, kailand!pat)
        System Manager, Kuck & Associates, Inc.

schaefer@ogccse.ogc.edu (Barton E. Schaefer) (07/28/89)

In article <8907280259.AA23361@kailand.kai.com> pwolfe@kailand.kai.COM (Patrick Wolfe) writes:
} There appears to be a bug in Mush 6.5.6 [...] macros activated by codes that
} end in tilde's.  I'm trying to use the "map" command in line mode to define
} commands to be executed when I press my VT220 compatible terminal's function
} keys.  These function keys all end with a tilde.
} 
} The command in my .mushrc is:
}         map '\E[20~' "echo f9 was pressed\n"
} 
} When I press function key "f9" after a prompt, instead of displaying the
} message, mush usually pauses for a second, then displays '^E[20~',

There are several possibilities here.

If this is truly a problem with tildes, the one that comes to mind is that
tilde is an escape character recognized by an intermediate program (e.g.
rlogin) that is running between your terminal connection and mush.  In the
case of rlogin, the tilde should be recognized only at beginning of line,
but stranger things have been known to happen.

If that isn't the problem, and I tend to doubt it that it is, then I suspect
the difficulty lies not with tildes but with the length of the sequence and
how quickly your terminal sends it.

} I say usually, because once in a while it works correctly, but about
} 90% of the time it doesn't.  I can't isolate any conditions that cause it to
} fail repeatedly.
} 
} If I manually type the key sequence in, it executes the macro correctly, and
} displays my message.  If I press the function key and then any other key
} immediately (such as the space bar), the macro is expanded perfectly.  If I
} [leave] off the tilde, it works every time, except for the unfortunate
} side effect of having a tilde placed at the beginning of the next command
} line.

This sounds like a symptom of a stdio/"raw"-io clash.  Mush's macro code
uses stdio functions for input (after placing the terminal in cbreak
mode) but is forced to rely on select() or ioctl() to test for timeout
conditions.  Most of the time, there is no problem, because cbreak mode
causes getchar() to receive one character and return immediately; no input
buffering ever happens.  Terminal function keys, however, when used on
very fast tty lines, can send characters so quickly that the tty driver
queue gets all of them before getchar() can wake up and grab the first one.
In that case, getchar() *might* actually consume all the characters
(depending on the state of the stdio buffers), leaving mush with no way to
tell that input is still pending.

You can't possibly type the sequence by hand fast enough for this to
happen, so it only fails when using the function key.  Typing another
character after the f9 sequence or omitting the last character from the
sequence will both interrupt the macro processing (in different ways),
causing the binding to "work".

} Can someone please help me find a way to get mush to reliably handle my
} function key macros?

Set your baud rate lower. :-(

The above suggests that mush really needs to quit using stdio. |-b
However, it also suggests a workaround:  use two mappings instead of one.

	map '\E[20' f9
	map 'f9~' "echo f9 was pressed\n"

Of course, you probably want to pick something other than "f9" for the
expansion of the first map.  The more I think about it, the less certain
I am that this will solve the problem, but it's worth a try.

Another possibility is to do a little fooling with mush's initialization.
File main.c, line numbers at the left:

    62      if (!isatty(0))
    63          turnon(glob_flags, REDIRECT);
+           else
+               (void) setbuf(stdin, NULL);
    64
    65      n = 0; /* don't ignore no such file or directory */

(No, that should not be considered an official patch.)  If any of you
try this, or recognize portability problems with it, let me know what
the results are; we can consider adding something like it to the beta
SunView version for further testing.  (It really ought to happen after
checks for echo mode are done; the above is just the most obvious place
to stick it in for a quick test.)
-- 
Bart Schaefer           "And if you believe that, you'll believe anything."
                                                            -- DangerMouse
CSNET / Internet                schaefer@cse.ogc.edu
UUCP                            ...{sequent,tektronix,verdix}!ogccse!schaefer

paul@devon.LNS.PA.US (Paul Sutcliffe Jr.) (07/31/89)

In article <8907280259.AA23361@kailand.kai.com>
pwolfe@kailand.kai.COM (Patrick Wolfe) writes:
+---------
| There appears to be a bug in Mush 6.5.6 [...]
+---------
                                    ^^^^^

My news feed was very intermittent the last few weeks.  Did I miss the
posting of patch #6, and if so, can someone e-mail it to me?

- paul

-- 
INTERNET:  paul@devon.LNS.PA.US         |   How many whales do you have to
UUCP:      ...!rutgers!devon!paul       |       save to get a toaster?