amuz.es/src/infra/goutils@v0.1.3/tty/code/termcodes_linux.go (about) 1 // +build linux 2 3 package code 4 5 import ( 6 "os" 7 "syscall" 8 "unsafe" 9 ) 10 11 type iflagSetter struct { 12 Flag uint32 13 } 14 15 type lflagSetter struct { 16 Flag uint32 17 } 18 19 type oflagSetter struct { 20 Flag uint32 21 } 22 23 type cflagSetter struct { 24 Flag uint32 25 } 26 27 func SetAttr(tty *os.File, termios *syscall.Termios) error { 28 r, _, e := syscall.Syscall(syscall.SYS_IOCTL, tty.Fd(), syscall.TCSETS, uintptr(unsafe.Pointer(termios))) 29 if r != 0 { 30 return os.NewSyscallError("SYS_IOCTL", e) 31 } 32 33 return nil 34 } 35 36 func GetAttr(tty *os.File) (*syscall.Termios, error) { 37 termios := &syscall.Termios{} 38 39 r, _, e := syscall.Syscall(syscall.SYS_IOCTL, tty.Fd(), syscall.TCGETS, uintptr(unsafe.Pointer(termios))) 40 if r != 0 { 41 return nil, os.NewSyscallError("SYS_IOCTL", e) 42 } 43 44 return termios, nil 45 }