Refactor tty code into its own package

This commit is contained in:
Kovid Goyal
2022-08-22 21:20:54 +05:30
parent 13758e9600
commit 246277e7af
5 changed files with 24 additions and 19 deletions

26
tools/tty/tty_bsd.go Normal file
View File

@@ -0,0 +1,26 @@
//go:build darwin || freebsd || openbsd || netbsd || dragonfly
// +build darwin freebsd openbsd netbsd dragonfly
package tty
import (
"golang.org/x/sys/unix"
)
func Tcgetattr(fd uintptr, argp *unix.Termios) error {
return unix.IoctlSetTermios(int(fd), unix.TIOCGETA, argp)
}
func Tcsetattr(fd, opt uintptr, argp *unix.Termios) error {
switch opt {
case TCSANOW:
opt = unix.TIOCSETA
case TCSADRAIN:
opt = unix.TIOCSETAW
case TCSAFLUSH:
opt = unix.TIOCSETAF
default:
return unix.EINVAL
}
return unix.IoctlSetTermios(int(fd), uint(opt), argp)
}