github.com/prattmic/llgo-embedded@v0.0.0-20150820070356-41cfecea0e1e/third_party/liner/unixmode.go (about) 1 // +build linux darwin freebsd openbsd netbsd 2 3 package liner 4 5 import ( 6 "syscall" 7 "unsafe" 8 ) 9 10 func (mode *termios) ApplyMode() error { 11 _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), setTermios, uintptr(unsafe.Pointer(mode))) 12 13 if errno != 0 { 14 return errno 15 } 16 return nil 17 } 18 19 // TerminalMode returns the current terminal input mode as an InputModeSetter. 20 // 21 // This function is provided for convenience, and should 22 // not be necessary for most users of liner. 23 func TerminalMode() (ModeApplier, error) { 24 mode, errno := getMode(syscall.Stdin) 25 26 if errno != 0 { 27 return nil, errno 28 } 29 return mode, nil 30 } 31 32 func getMode(handle int) (*termios, syscall.Errno) { 33 var mode termios 34 _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(handle), getTermios, uintptr(unsafe.Pointer(&mode))) 35 36 return &mode, errno 37 }