term_linux.go 567 B

123456789101112131415161718192021222324252627282930
  1. //go:build linux || solaris
  2. package readline
  3. import (
  4. "syscall"
  5. "unsafe"
  6. )
  7. const (
  8. tcgets = 0x5401
  9. tcsets = 0x5402
  10. )
  11. func getTermios(fd uintptr) (*Termios, error) {
  12. termios := new(Termios)
  13. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, tcgets, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
  14. if err != 0 {
  15. return nil, err
  16. }
  17. return termios, nil
  18. }
  19. func setTermios(fd uintptr, termios *Termios) error {
  20. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, tcsets, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
  21. if err != 0 {
  22. return err
  23. }
  24. return nil
  25. }