term_bsd.go 564 Bytes
Newer Older
1
//go:build darwin || freebsd || netbsd || openbsd
Michael Yang's avatar
go fmt  
Michael Yang committed
2

Patrick Devine's avatar
Patrick Devine committed
3
4
5
6
7
8
9
package readline

import (
	"syscall"
	"unsafe"
)

Michael Yang's avatar
Michael Yang committed
10
func getTermios(fd uintptr) (*Termios, error) {
Patrick Devine's avatar
Patrick Devine committed
11
	termios := new(Termios)
Michael Yang's avatar
Michael Yang committed
12
	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, syscall.TIOCGETA, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
Patrick Devine's avatar
Patrick Devine committed
13
14
15
16
17
18
	if err != 0 {
		return nil, err
	}
	return termios, nil
}

Michael Yang's avatar
Michael Yang committed
19
20
func setTermios(fd uintptr, termios *Termios) error {
	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, syscall.TIOCSETA, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
Patrick Devine's avatar
Patrick Devine committed
21
22
23
24
25
	if err != 0 {
		return err
	}
	return nil
}