term_linux.go 577 B

12345678910111213141516171819202122232425262728
  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 int) (*Termios, error) {
  10. termios := new(Termios)
  11. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(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 int, termios *Termios) error {
  18. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), tcsets, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
  19. if err != 0 {
  20. return err
  21. }
  22. return nil
  23. }