term_linux.go 567 Bytes
Newer Older
mashun1's avatar
v1  
mashun1 committed
1
2
3
4
5
6
7
8
9
//go:build linux || solaris

package readline

import (
	"syscall"
	"unsafe"
)

xuxzh1's avatar
init  
xuxzh1 committed
10
11
12
13
const (
	tcgets = 0x5401
	tcsets = 0x5402
)
mashun1's avatar
v1  
mashun1 committed
14

xuxzh1's avatar
init  
xuxzh1 committed
15
func getTermios(fd uintptr) (*Termios, error) {
mashun1's avatar
v1  
mashun1 committed
16
	termios := new(Termios)
xuxzh1's avatar
init  
xuxzh1 committed
17
	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, tcgets, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
mashun1's avatar
v1  
mashun1 committed
18
19
20
21
22
23
	if err != 0 {
		return nil, err
	}
	return termios, nil
}

xuxzh1's avatar
init  
xuxzh1 committed
24
25
func setTermios(fd uintptr, termios *Termios) error {
	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, tcsets, uintptr(unsafe.Pointer(termios)), 0, 0, 0)
mashun1's avatar
v1  
mashun1 committed
26
27
28
29
30
	if err != 0 {
		return err
	}
	return nil
}