nsf / termbox-go

Pure Go termbox implementation
http://godoc.org/github.com/nsf/termbox-go
MIT License
4.66k stars 372 forks source link

macOS delay on incomplete escape sequences to avoid spurious escape keypress detection #132 #176

Closed rationull closed 6 years ago

rationull commented 6 years ago

This proposed solution to the macOS partial escape sequence problem can be contrasted against #158 (which is similar to another proposal from the comment thread on #132). Compared with that solution, this one is more complicated but will handle the case where an escape sequence is interrupted such that ONLY the escape character comes through ahead of the rest of the sequence. It's not proven whether that's possible since AFAICT we don't understand the mechanism by which the escape sequences are being split up in macOS, but then the whole problem here is nondeterminism.

Also this solution relies on an arbitrary delay which works according to my testing but is not verifiably "correct". This causes an short delay in processing of plain Escape keypresses. The delay is supposed to be long enough to let long escape sequences finish, but short enough not to be noticeable by the user. I have it set to 50 ms in my commit but this is obviously debatable and subject to observed behavior.

Whether this solution is better than the simpler one (if the simpler one were modified to be macOS only) I leave up to @nsf :)

Outline of this solution: