term_linux.go 567 Bytes
Newer Older
1
//go:build linux || solaris
Michael Yang's avatar
go fmt  
Michael Yang committed
2

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

import (
	"syscall"
	"unsafe"
)

const tcgets = 0x5401
const tcsets = 0x5402

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

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