-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsyscall_unix.go
57 lines (47 loc) · 1.3 KB
/
syscall_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2010 Jonas mg
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// +build !plan9,!windows
/* Reference: man termios ; man tty_ioctl */
package terminal
import (
"syscall"
"unsafe"
)
//sys int tcgetattr(int fd, struct termios *termios_p)
func tcgetattr(fd int, state *termios) (err error) {
_, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd),
uintptr(_TCGETS), uintptr(unsafe.Pointer(state)))
if e1 != 0 {
err = e1
}
return
}
//sys int tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
func tcsetattr(fd int, action uint, state *termios) (err error) {
switch action {
case _TCSANOW:
action = _TCSETS
case _TCSADRAIN:
action = _TCSETSW
case _TCSAFLUSH:
action = _TCSETSF
}
_, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd),
uintptr(action), uintptr(unsafe.Pointer(state)))
if e1 != 0 {
err = e1
}
return
}
// getWinsize gets the winsize struct with the terminal size set by the kernel.
func getWinsize(fd int, ws *winsize) (err error) {
_, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd),
uintptr(_TIOCGWINSZ), uintptr(unsafe.Pointer(ws)))
if e1 != 0 {
err = e1
}
return
}