Wait for additional keys after ESC for up to 100ms

Close #661
This commit is contained in:
Junegunn Choi 2016-11-08 03:07:26 +09:00
parent 4accc69022
commit d206949f62
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -295,13 +295,24 @@ func getch(nonblock bool) int {
func GetBytes() []byte {
c := getch(false)
retries := 0
if c == 27 {
// Wait for additional keys after ESC for 100ms (10 * 10ms)
retries = 10
}
_buf = append(_buf, byte(c))
for {
c = getch(true)
if c == -1 {
if retries > 0 {
retries--
time.Sleep(10 * time.Millisecond)
continue
}
break
}
retries = 0
_buf = append(_buf, byte(c))
}