package termios
import (
"syscall"
"golang.org/x/sys/unix"
)
func SetWinsize (fd int , w *unix .Winsize ) error {
return unix .IoctlSetWinsize (fd , ioctlSetWinSize , w )
}
func GetWinsize (fd int ) (*unix .Winsize , error ) {
return unix .IoctlGetWinsize (fd , ioctlSetWinSize )
}
func GetTermios (fd int ) (*unix .Termios , error ) {
return unix .IoctlGetTermios (fd , ioctlGets )
}
func SetTermios (
fd int ,
ispeed uint32 ,
ospeed uint32 ,
cc map [CC ]uint8 ,
iflag map [I ]bool ,
oflag map [O ]bool ,
cflag map [C ]bool ,
lflag map [L ]bool ,
) error {
term , err := unix .IoctlGetTermios (fd , ioctlGets )
if err != nil {
return err
}
setSpeed (term , ispeed , ospeed )
for key , value := range cc {
call , ok := allCcOpts [key ]
if !ok {
continue
}
term .Cc [call ] = value
}
for key , value := range iflag {
mask , ok := allInputOpts [key ]
if ok {
if value {
term .Iflag |= bit (mask )
} else {
term .Iflag &= ^bit (mask )
}
}
}
for key , value := range oflag {
mask , ok := allOutputOpts [key ]
if ok {
if value {
term .Oflag |= bit (mask )
} else {
term .Oflag &= ^bit (mask )
}
}
}
for key , value := range cflag {
mask , ok := allControlOpts [key ]
if ok {
if value {
term .Cflag |= bit (mask )
} else {
term .Cflag &= ^bit (mask )
}
}
}
for key , value := range lflag {
mask , ok := allLineOpts [key ]
if ok {
if value {
term .Lflag |= bit (mask )
} else {
term .Lflag &= ^bit (mask )
}
}
}
return unix .IoctlSetTermios (fd , ioctlSets , term )
}
type CC uint8
const (
INTR CC = iota
QUIT
ERASE
KILL
EOF
EOL
EOL2
START
STOP
SUSP
WERASE
RPRNT
LNEXT
DISCARD
STATUS
SWTCH
DSUSP
FLUSH
)
var allCcOpts = map [CC ]int {
INTR : syscall .VINTR ,
QUIT : syscall .VQUIT ,
ERASE : syscall .VERASE ,
KILL : syscall .VQUIT ,
EOF : syscall .VEOF ,
EOL : syscall .VEOL ,
EOL2 : syscall .VEOL2 ,
START : syscall .VSTART ,
STOP : syscall .VSTOP ,
SUSP : syscall .VSUSP ,
WERASE : syscall .VWERASE ,
RPRNT : syscall .VREPRINT ,
LNEXT : syscall .VLNEXT ,
DISCARD : syscall .VDISCARD ,
}
type I uint8
const (
IGNPAR I = iota
PARMRK
INPCK
ISTRIP
INLCR
IGNCR
ICRNL
IXON
IXANY
IXOFF
IMAXBEL
IUCLC
)
var allInputOpts = map [I ]uint32 {
IGNPAR : syscall .IGNPAR ,
PARMRK : syscall .PARMRK ,
INPCK : syscall .INPCK ,
ISTRIP : syscall .ISTRIP ,
INLCR : syscall .INLCR ,
IGNCR : syscall .IGNCR ,
ICRNL : syscall .ICRNL ,
IXON : syscall .IXON ,
IXANY : syscall .IXANY ,
IXOFF : syscall .IXOFF ,
IMAXBEL : syscall .IMAXBEL ,
}
type O uint8
const (
OPOST O = iota
ONLCR
OCRNL
ONOCR
ONLRET
OLCUC
)
var allOutputOpts = map [O ]uint32 {
OPOST : syscall .OPOST ,
ONLCR : syscall .ONLCR ,
OCRNL : syscall .OCRNL ,
ONOCR : syscall .ONOCR ,
ONLRET : syscall .ONLRET ,
}
type C uint8
const (
CS7 C = iota
CS8
PARENB
PARODD
)
var allControlOpts = map [C ]uint32 {
CS7 : syscall .CS7 ,
CS8 : syscall .CS8 ,
PARENB : syscall .PARENB ,
PARODD : syscall .PARODD ,
}
type L uint8
const (
ISIG L = iota
ICANON
ECHO
ECHOE
ECHOK
ECHONL
NOFLSH
TOSTOP
IEXTEN
ECHOCTL
ECHOKE
PENDIN
IUTF8
XCASE
)
var allLineOpts = map [L ]uint32 {
ISIG : syscall .ISIG ,
ICANON : syscall .ICANON ,
ECHO : syscall .ECHO ,
ECHOE : syscall .ECHOE ,
ECHOK : syscall .ECHOK ,
ECHONL : syscall .ECHONL ,
NOFLSH : syscall .NOFLSH ,
TOSTOP : syscall .TOSTOP ,
IEXTEN : syscall .IEXTEN ,
ECHOCTL : syscall .ECHOCTL ,
ECHOKE : syscall .ECHOKE ,
PENDIN : syscall .PENDIN ,
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .