ollama/readline/term_bsd.go

26 lines
564 B
Go
Raw Normal View History

2023-10-27 03:00:33 +08:00
//go:build darwin || freebsd || netbsd || openbsd
2023-11-02 02:55:08 +08:00
2023-10-26 07:41:18 +08:00
package readline
import (
"syscall"
"unsafe"
)
2024-05-23 00:00:38 +08:00
func getTermios(fd uintptr) (*Termios, error) {
2023-10-26 07:41:18 +08:00
termios := new(Termios)
2024-05-23 00:00:38 +08:00
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, syscall.TIOCGETA, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
2023-10-26 07:41:18 +08:00
if err != 0 {
return nil, err
}
return termios, nil
}
2024-05-23 00:00:38 +08:00
func setTermios(fd uintptr, termios *Termios) error {
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, syscall.TIOCSETA, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
2023-10-26 07:41:18 +08:00
if err != 0 {
return err
}
return nil
}