summaryrefslogtreecommitdiffstats
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-11-23 02:18:18 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-11-23 02:28:03 +0900
commit43425158f4fbb961d5c365d39664912a7ebf9342 (patch)
treefa4ac617602079b70bf2f66e390b88646a20ce37 /src/tui
parent8524ea74414cfe0773a4318a6b4d9da87e230a07 (diff)
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.
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/ncurses.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/tui/ncurses.go b/src/tui/ncurses.go
index 5a4d5382..8603fd32 100644
--- a/src/tui/ncurses.go
+++ b/src/tui/ncurses.go
@@ -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: