unixmode.go 840 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // +build linux darwin freebsd openbsd netbsd
  2. package liner
  3. import (
  4. "syscall"
  5. "unsafe"
  6. )
  7. func (mode *termios) ApplyMode() error {
  8. _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), setTermios, uintptr(unsafe.Pointer(mode)))
  9. if errno != 0 {
  10. return errno
  11. }
  12. return nil
  13. }
  14. // TerminalMode returns the current terminal input mode as an InputModeSetter.
  15. //
  16. // This function is provided for convenience, and should
  17. // not be necessary for most users of liner.
  18. func TerminalMode() (ModeApplier, error) {
  19. mode, errno := getMode(syscall.Stdin)
  20. if errno != 0 {
  21. return nil, errno
  22. }
  23. return mode, nil
  24. }
  25. func getMode(handle int) (*termios, syscall.Errno) {
  26. var mode termios
  27. _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(handle), getTermios, uintptr(unsafe.Pointer(&mode)))
  28. return &mode, errno
  29. }