Re: Press any key to continue... bug?



On Wed, 19 Nov 2003, Miven Dooligan wrote:

> A little thing that's been bugging me for quite a long time: Using mc I
> get the habit of F10 to cancel things, so when I run something from the
> F2 user menu and it asks me to "Press any key to continue..." I seem to
> tap F10 by habit, which leaves a bunch of junk on the command line when
> the panels return, which I have to backspace though. This little hack
> uses read() to suck the keyboard dry so that I'm not left with chars in
> the buffer, and I have a nice clean commandline.
>
> Does this seem like a reasonable approach?

I don't think it's a reasonable approach because it doesn't use the code
already present in mc specifically for this purpose - to get a complete
key sequence.  The function is called get_key_code(), and it's already
used to return from Ctrl-O if the subshell is not used.  I've just applied
a patch that uses get_key_code() for the "pause after run".

Another reason your patch is incorrect is because it relies on the
behavior of read().  It's not safe to rely on it, especially for remote
terminals.  There is no guarantee that it will flush the input.  Again,
there is a standard function specifically for flushing the input on
terminals.  You can find it used in synchronize() (src/subshell.c):

    /* Discard all remaining data from stdin to the subshell */
    tcflush (subshell_pty, TCOFLUSH);

I don't think we need to flush the input in this particular case because
there may be legitimate uses for typing ahead.  You can press "any key"
and start typing another command.  It's different from the situation where
tcflush() is currently used, where the output would be fed to the subshell
(not the command line) after the panels are restored.

It's important to keep the code consistent and to reuse the existing code.
Less code usually means less bugs, and if there are bugs, they are easier
to detect and fix.

-- 
Regards,
Pavel Roskin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]