tty_linux.go 728 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package tty
  3. import "golang.org/x/sys/unix"
  4. const (
  5. TCSETS = 0x5402
  6. TCSETSW = 0x5403
  7. TCSETSF = 0x5404
  8. TCFLSH = 0x540B
  9. TCSBRK = 0x5409
  10. TCSBRKP = 0x5425
  11. IXON = 0x00000400
  12. IXANY = 0x00000800
  13. IXOFF = 0x00001000
  14. CRTSCTS = 0x80000000
  15. )
  16. func Tcgetattr(fd int, argp *unix.Termios) error {
  17. return unix.IoctlSetTermios(fd, unix.TCGETS, argp)
  18. }
  19. func Tcsetattr(fd int, action uintptr, argp *unix.Termios) error {
  20. var request uint
  21. switch action {
  22. case TCSANOW:
  23. request = TCSETS
  24. case TCSADRAIN:
  25. request = TCSETSW
  26. case TCSAFLUSH:
  27. request = TCSETSF
  28. default:
  29. return unix.EINVAL
  30. }
  31. return unix.IoctlSetTermios(fd, request, argp)
  32. }