Skip to content
Snippets Groups Projects
Unverified Commit 43425158 authored by Junegunn Choi's avatar Junegunn Choi
Browse files

Make escape delay configurable via ncurses standard $ESCDELAY

Also reduce the default delay to 50ms. We should not set it to 0ms as it
breaks escape sequences on WSL. If 50ms is not enough, one can increase
the delay by setting $ESCDELAY to a larger value.
parent 8524ea74
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ import "C"
import (
"fmt"
"os"
"strconv"
"strings"
"time"
"unicode/utf8"
......@@ -103,8 +104,16 @@ func Init(theme *ColorTheme, black bool, mouse bool) {
C.raw() // stty dsusp undef
C.nonl()
C.keypad(C.stdscr, true)
C.set_escdelay(100)
C.timeout(100) // ESCDELAY 100ms + timeout 100ms
delay := 50
delayEnv := os.Getenv("ESCDELAY")
if len(delayEnv) > 0 {
num, err := strconv.Atoi(delayEnv)
if err == nil && num >= 0 {
delay = num
}
}
C.set_escdelay(C.int(delay))
_color = theme != nil
if _color {
......@@ -293,8 +302,10 @@ func consume(expects ...rune) bool {
}
func escSequence() Event {
// nodelay is not thread-safe (e.g. <ESC><CTRL-P>)
// C.nodelay(C.stdscr, true)
C.nodelay(C.stdscr, true)
defer func() {
C.nodelay(C.stdscr, false)
}()
c := C.getch()
switch c {
case C.ERR:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment