termios.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // +build !windows
  2. package termios
  3. import (
  4. "unsafe"
  5. "golang.org/x/sys/unix"
  6. )
  7. // Tiocmget returns the state of the MODEM bits.
  8. func Tiocmget(fd uintptr, status *int) error {
  9. return ioctl(fd, unix.TIOCMGET, uintptr(unsafe.Pointer(status)))
  10. }
  11. // Tiocmset sets the state of the MODEM bits.
  12. func Tiocmset(fd uintptr, status *int) error {
  13. return ioctl(fd, unix.TIOCMSET, uintptr(unsafe.Pointer(status)))
  14. }
  15. // Tiocmbis sets the indicated modem bits.
  16. func Tiocmbis(fd uintptr, status *int) error {
  17. return ioctl(fd, unix.TIOCMBIS, uintptr(unsafe.Pointer(status)))
  18. }
  19. // Tiocmbic clears the indicated modem bits.
  20. func Tiocmbic(fd uintptr, status *int) error {
  21. return ioctl(fd, unix.TIOCMBIC, uintptr(unsafe.Pointer(status)))
  22. }
  23. // Cfmakecbreak modifies attr for cbreak mode.
  24. func Cfmakecbreak(attr *unix.Termios) {
  25. attr.Lflag &^= unix.ECHO | unix.ICANON
  26. attr.Cc[unix.VMIN] = 1
  27. attr.Cc[unix.VTIME] = 0
  28. }
  29. // Cfmakeraw modifies attr for raw mode.
  30. func Cfmakeraw(attr *unix.Termios) {
  31. attr.Iflag &^= unix.BRKINT | unix.ICRNL | unix.INPCK | unix.ISTRIP | unix.IXON
  32. attr.Oflag &^= unix.OPOST
  33. attr.Cflag &^= unix.CSIZE | unix.PARENB
  34. attr.Cflag |= unix.CS8
  35. attr.Lflag &^= unix.ECHO | unix.ICANON | unix.IEXTEN | unix.ISIG
  36. attr.Cc[unix.VMIN] = 1
  37. attr.Cc[unix.VTIME] = 0
  38. }