2023-10-26 19:00:33 +00:00
|
|
|
//go:build linux || solaris
|
2023-11-01 18:55:08 +00:00
|
|
|
|
2023-10-25 23:41:18 +00:00
|
|
|
package readline
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2024-08-01 21:52:15 +00:00
|
|
|
const (
|
|
|
|
tcgets = 0x5401
|
|
|
|
tcsets = 0x5402
|
|
|
|
)
|
2023-10-25 23:41:18 +00:00
|
|
|
|
2024-05-22 16:00:38 +00:00
|
|
|
func getTermios(fd uintptr) (*Termios, error) {
|
2023-10-25 23:41:18 +00:00
|
|
|
termios := new(Termios)
|
2024-05-22 16:00:38 +00:00
|
|
|
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, tcgets, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
|
2023-10-25 23:41:18 +00:00
|
|
|
if err != 0 {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return termios, nil
|
|
|
|
}
|
|
|
|
|
2024-05-22 16:00:38 +00:00
|
|
|
func setTermios(fd uintptr, termios *Termios) error {
|
|
|
|
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, tcsets, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
|
2023-10-25 23:41:18 +00:00
|
|
|
if err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|