term_linux.go 567 B

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