term_linux.go 548 B

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