-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathioctl_sysunix.go
43 lines (33 loc) · 941 Bytes
/
ioctl_sysunix.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
// +build aix solaris
// Copyright 2013-2015 Bowery, Inc.
package prompt
import (
"os"
"golang.org/x/sys/unix"
)
const (
tcgets = unix.TCGETS
tcsetsf = unix.TCSETSF
tcsets = unix.TCSETS
)
// terminalSize retrieves the cols/rows for the terminal connected to out.
func terminalSize(out *os.File) (int, int, error) {
ws, err := unix.IoctlGetWinsize(int(out.Fd()), unix.TIOCGWINSZ)
if err != nil {
return 0, 0, err
}
return int(ws.Col), int(ws.Row), nil
}
// getTermios retrieves the termios settings for the terminal descriptor.
func getTermios(fd uintptr) (*unix.Termios, error) {
return unix.IoctlGetTermios(int(fd), tcgets)
}
// setTermios sets the termios settings for the terminal descriptor,
// optionally flushing the buffer before setting.
func setTermios(fd uintptr, flush bool, mode *unix.Termios) error {
req := tcsets
if flush {
req = tcsetsf
}
return unix.IoctlSetTermios(int(fd), uint(req), mode)
}