The "loop and a half"

Peter J. Holzer hjp-usenet3 at hjp.at
Sun Oct 8 09:41:17 EDT 2017


On 2017-10-07 08:35, Steve D'Aprano <steve+python at pearwood.info> wrote:
> Unfortunately ESCAPE is already used. VT100 (the terminal emulation which is
> used in just about all terminals) all control sequences begin with ESC. So
> every time you do something like press an arrow key, the terminal sends ESC
> followed by other stuff. It would be painful if every time you hit an arrow
> key, the interpreter took it as "Exit".

The usual solution to this problem is to use a timeout: If ESC is not
followed by another character which could continue the sequence within
e.g. 0.1 seconds it is interpreted as a standalone key press instead of
the start of an escape sequence. This is not 100% reliable: If you are
on a jittery network connection, the O in the cursor-up sequence might
arrive more than 0.1 seconds after the ESC - or the the three distinct
keystrokes ESC O A might be delivered in the same packet.

        hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp at hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel



More information about the Python-list mailing list