func (w *Window) Nodelay(nodelay bool) { if nodelay { C.nodelay(w.win, 1) } else { C.nodelay(w.win, 0) } }
func Init(theme *ColorTheme, black bool, mouse bool) { C.setlocale(C.LC_ALL, C.CString("")) tty := C.c_tty() if tty == nil { fmt.Println("Failed to open /dev/tty") os.Exit(2) } _screen = C.c_newterm(tty) if _screen == nil { fmt.Println("Invalid $TERM: " + os.Getenv("TERM")) os.Exit(2) } C.set_term(_screen) if mouse { C.mousemask(C.ALL_MOUSE_EVENTS, nil) C.mouseinterval(0) } C.noecho() C.raw() // stty dsusp undef C.nonl() C.keypad(C.stdscr, true) 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 { C.start_color() InitTheme(theme, black) initPairs(theme) C.bkgd(C.chtype(C.COLOR_PAIR(C.int(ColNormal)))) _colorFn = attrColored } else { _colorFn = attrMono } C.nodelay(C.stdscr, true) ch := C.getch() if ch != C.ERR { C.ungetch(ch) } C.nodelay(C.stdscr, false) }
func (r *FullscreenRenderer) Init() { C.setlocale(C.LC_ALL, C.CString("")) tty := C.c_tty() if tty == nil { errorExit("Failed to open /dev/tty") } _screen = C.c_newterm(tty) if _screen == nil { errorExit("Invalid $TERM: " + os.Getenv("TERM")) } C.set_term(_screen) if r.mouse { C.mousemask(C.ALL_MOUSE_EVENTS, nil) C.mouseinterval(0) } C.noecho() C.raw() // stty dsusp undef C.nonl() C.keypad(C.stdscr, true) 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)) if r.theme != nil { C.start_color() initTheme(r.theme, r.defaultTheme(), r.forceBlack) initPairs(r.theme) C.bkgd(C.chtype(C.COLOR_PAIR(C.int(ColNormal.index())))) _colorFn = attrColored } else { initTheme(r.theme, nil, r.forceBlack) _colorFn = attrMono } C.nodelay(C.stdscr, true) ch := C.getch() if ch != C.ERR { C.ungetch(ch) } C.nodelay(C.stdscr, false) }
func (win *Window) Nodelay(b bool) error { a := bool2cint(b) r := C.nodelay((*C.WINDOW)(win), a) if r == C.ERR { return CursesError{"nodelay failed"} } return nil }
func escSequence() Event { C.nodelay(C.stdscr, true) defer func() { C.nodelay(C.stdscr, false) }() c := C.getch() switch c { case C.ERR: return Event{ESC, 0, nil} case CtrlM: return Event{AltEnter, 0, nil} case '/': return Event{AltSlash, 0, nil} case ' ': return Event{AltSpace, 0, nil} case 127, C.KEY_BACKSPACE: return Event{AltBS, 0, nil} case '[': // Bracketed paste mode (printf "\e[?2004h") // \e[200~ TEXT \e[201~ if consume('2', '0', '0', '~') { return Event{Invalid, 0, nil} } } if c >= 'a' && c <= 'z' { return Event{AltA + int(c) - 'a', 0, nil} } if c >= '0' && c <= '9' { return Event{Alt0 + int(c) - '0', 0, nil} } // Don't care. Ignore the rest. for ; c != C.ERR; c = C.getch() { } return Event{Invalid, 0, nil} }