raw.go 748 B

1234567891011121314151617181920212223242526272829
  1. // +build !windows
  2. package term
  3. import (
  4. "syscall"
  5. "github.com/pkg/term/termios"
  6. "golang.org/x/sys/unix"
  7. )
  8. // SetRaw put terminal into a raw mode
  9. func SetRaw(fd int) error {
  10. n, err := getOriginalTermios(fd)
  11. if err != nil {
  12. return err
  13. }
  14. n.Iflag &^= syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK |
  15. syscall.ISTRIP | syscall.INLCR | syscall.IGNCR |
  16. syscall.ICRNL | syscall.IXON
  17. n.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.IEXTEN | syscall.ISIG | syscall.ECHONL
  18. n.Cflag &^= syscall.CSIZE | syscall.PARENB
  19. n.Cflag |= syscall.CS8 // Set to 8-bit wide. Typical value for displaying characters.
  20. n.Cc[syscall.VMIN] = 1
  21. n.Cc[syscall.VTIME] = 0
  22. return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*unix.Termios)(&n))
  23. }