termios_unix.go 805 B

1234567891011121314151617181920212223242526272829303132333435
  1. //go:build !windows
  2. // +build !windows
  3. package term
  4. import (
  5. "golang.org/x/sys/unix"
  6. )
  7. // Termios is the Unix API for terminal I/O.
  8. //
  9. // Deprecated: use [unix.Termios].
  10. type Termios = unix.Termios
  11. func makeRaw(fd uintptr) (*State, error) {
  12. termios, err := tcget(fd)
  13. if err != nil {
  14. return nil, err
  15. }
  16. oldState := State{termios: *termios}
  17. termios.Iflag &^= unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON
  18. termios.Oflag &^= unix.OPOST
  19. termios.Lflag &^= unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN
  20. termios.Cflag &^= unix.CSIZE | unix.PARENB
  21. termios.Cflag |= unix.CS8
  22. termios.Cc[unix.VMIN] = 1
  23. termios.Cc[unix.VTIME] = 0
  24. if err := tcset(fd, termios); err != nil {
  25. return nil, err
  26. }
  27. return &oldState, nil
  28. }