You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
964 B

  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package readline
  5. import (
  6. "syscall"
  7. "unsafe"
  8. )
  9. // These constants are declared here, rather than importing
  10. // them from the syscall package as some syscall packages, even
  11. // on linux, for example gccgo, do not declare them.
  12. const ioctlReadTermios = 0x5401 // syscall.TCGETS
  13. const ioctlWriteTermios = 0x5402 // syscall.TCSETS
  14. func getTermios(fd int) (*Termios, error) {
  15. termios := new(Termios)
  16. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
  17. if err != 0 {
  18. return nil, err
  19. }
  20. return termios, nil
  21. }
  22. func setTermios(fd int, termios *Termios) error {
  23. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlWriteTermios, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
  24. if err != 0 {
  25. return err
  26. }
  27. return nil
  28. }