File: termios.go

package info (click to toggle)
golang-github-pkg-term 1.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 244 kB
  • sloc: makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,228 bytes parent folder | download | duplicates (3)
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
// +build !windows

package termios

import (
	"golang.org/x/sys/unix"
)

// Tiocmget returns the state of the MODEM bits.
func Tiocmget(fd uintptr) (int, error) {
	return unix.IoctlGetInt(int(fd), unix.TIOCMGET)
}

// Tiocmset sets the state of the MODEM bits.
func Tiocmset(fd uintptr, status int) error {
	return unix.IoctlSetInt(int(fd), unix.TIOCMSET, status)
}

// Tiocmbis sets the indicated modem bits.
func Tiocmbis(fd uintptr, status int) error {
	return unix.IoctlSetPointerInt(int(fd), unix.TIOCMBIS, status)
}

// Tiocmbic clears the indicated modem bits.
func Tiocmbic(fd uintptr, status int) error {
	return unix.IoctlSetPointerInt(int(fd), unix.TIOCMBIC, status)
}

// Cfmakecbreak modifies attr for cbreak mode.
func Cfmakecbreak(attr *unix.Termios) {
	attr.Lflag &^= unix.ECHO | unix.ICANON
	attr.Cc[unix.VMIN] = 1
	attr.Cc[unix.VTIME] = 0
}

// Cfmakeraw modifies attr for raw mode.
func Cfmakeraw(attr *unix.Termios) {
	attr.Iflag &^= unix.BRKINT | unix.ICRNL | unix.INPCK | unix.ISTRIP | unix.IXON
	attr.Oflag &^= unix.OPOST
	attr.Cflag &^= unix.CSIZE | unix.PARENB
	attr.Cflag |= unix.CS8
	attr.Lflag &^= unix.ECHO | unix.ICANON | unix.IEXTEN | unix.ISIG
	attr.Cc[unix.VMIN] = 1
	attr.Cc[unix.VTIME] = 0
}