Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix escape codes splitting across getBlockOfChars #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

goertzenator
Copy link

@goertzenator goertzenator commented May 27, 2021

This patch adds a 20ms timeout to getBlockOfChars when an ESC character is seen. This forces getBlockOfChars to wait for a whole escape sequence which could otherwise get fragmented on a slow connection.

Some useful reference information on this topic:
https://stackoverflow.com/a/3219355/398021

Fixes issue #160

- fixes issue haskell#160 and maybe issue haskell#77.
- 20ms delay worked well for 9600bps serial port, 10ms did not.
@Bodigrim
Copy link
Collaborator

haskeline is a GHC boot library, it cannot depend on async unfortunately.

@goertzenator
Copy link
Author

goertzenator commented Feb 19, 2025

I don't have time to dive into this right now but I would like to lay out a few thoughts:

  • It would be worth looking at some other mature terminal program such as Putty software to see how the ESC character is managed.
  • An incremental parser like the one found in the binary package might be the right approach. Pair that with a timeout symbol injected into the input stream to distinguish a naked ESC from an unfinished ESC code. This is of course a more significant change.
  • The current PR only addresses Posix. A complete fix would also address Win32, but I have not looked closely enough at the Win32 code to see if it is even affected.

edit: fixed Putty nonsense.. I was thinking at the wrong end.

@goertzenator
Copy link
Author

Excerpt from https://www.man7.org/linux/man-pages/man3/readline.3.html . So readline appears to default to a very large timeout of 500ms.

       keyseq-timeout (500)
              Specifies the duration readline will wait for a character
              when reading an ambiguous key sequence (one that can form a
              complete key sequence using the input read so far, or can
              take additional input to complete a longer key sequence).
              If no input is received within the timeout, readline will
              use the shorter but complete key sequence.  The value is
              specified in milliseconds, so a value of 1000 means that
              readline will wait one second for additional input.  If
              this variable is set to a value less than or equal to zero,
              or to a non-numeric value, readline will wait until another
              key is pressed to decide which key sequence to complete.```

@goertzenator
Copy link
Author

Another data point from rustyline. This library allows you to specify the timeout:

https://github.com/kkawakam/rustyline/blob/91f616a1c8e3208cffae7d9912446f850474d65f/src/config.rs#L545-L556

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants