judah / haskeline

A Haskell library for line input in command-line programs.
https://hackage.haskell.org/package/haskeline
BSD 3-Clause "New" or "Revised" License
221 stars 75 forks source link

Escape code not recognized across reads #160

Open goertzenator opened 3 years ago

goertzenator commented 3 years ago

When using the arrow keys in an application running on a 9600 baud serial port I get frequent garbage characters such as [A and [D which are of course broken escape codes.

This source code has the following comment:

-- Read at least one character of input, and more if immediately
-- available.  In particular the characters making up a control sequence
-- will all be available at once, so they can be processed together
-- (with Posix.lexKeys).

I don't think that is a workable assumption on a slow serial port.

I originally detected this issue in an oddball serial port and pseudo terminal configuration which gave me an easy way to inspect traffic:

pump1 got"\ESC[C"
pump1 got"\ESC[C"
pump1 got"\ESC[C"
pump1 got"\ESC"
pump1 got"[C"

In this example I pressed right arrow 4 times. It worked correctly 3 times and then I got [C on the screen. The correct data is getting through, but it is clearly not interpreting the escape code.

Escape codes should still be recognized even if they do not arrive all at once.

Possibly related to case #77.