-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmain_bsd.go
More file actions
33 lines (26 loc) · 777 Bytes
/
main_bsd.go
File metadata and controls
33 lines (26 loc) · 777 Bytes
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
// +build darwin dragonfly freebsd netbsd openbsd
package main
import (
"log"
"os"
"golang.org/x/sys/unix"
)
func disableEcho() *unix.Termios {
termios, err := unix.IoctlGetTermios(int(os.Stdout.Fd()), unix.TIOCGETA)
if err != nil {
log.Fatalf("failed to get the termios: %v", err)
}
newState := *termios
newState.Lflag &^= unix.ECHO
newState.Lflag |= unix.ICANON | unix.ISIG
newState.Iflag |= unix.ICRNL
if err := unix.IoctlSetTermios(int(os.Stdout.Fd()), unix.TIOCSETA, &newState); err != nil {
log.Fatalf("failed to set the termios: %v", err)
}
return termios
}
func enableEcho(termios *unix.Termios) {
if err := unix.IoctlSetTermios(int(os.Stdout.Fd()), unix.TIOCSETA, termios); err != nil {
log.Fatalf("failed to set the termios: %v", err)
}
}