Add support for macOS

This commit is contained in:
Kevin Cotugno 2020-09-28 20:27:37 -07:00
parent 442e406f55
commit 0f8d3f8f3a
3 changed files with 25 additions and 5 deletions

View File

@ -1,8 +1,6 @@
package exhibit
import (
"golang.org/x/sys/unix"
"bytes"
"fmt"
"io"
@ -11,6 +9,8 @@ import (
"sync"
"time"
"unicode/utf8"
"golang.org/x/sys/unix"
)
const (
@ -69,7 +69,7 @@ func Init() *Terminal {
log.Panic(err)
}
termios, err := unix.IoctlGetTermios(int(out.Fd()), unix.TCGETS)
termios, err := unix.IoctlGetTermios(int(out.Fd()), ioctlReadTermios)
if err != nil {
out.Close()
in.Close()
@ -408,7 +408,7 @@ func (t *Terminal) enterRaw() {
termios.Cc[unix.VMIN] = 1
termios.Cc[unix.VTIME] = 0
err := unix.IoctlSetTermios(t.outFd(), unix.TCSETS, &termios)
err := unix.IoctlSetTermios(t.outFd(), ioctlWriteTermios, &termios)
if err != nil {
t.exitAlt()
t.out.Close()
@ -418,7 +418,7 @@ func (t *Terminal) enterRaw() {
}
func (t *Terminal) exitRaw() {
err := unix.IoctlSetTermios(t.outFd(), unix.TCSETS, &t.termios)
err := unix.IoctlSetTermios(t.outFd(), ioctlWriteTermios, &t.termios)
if err != nil {
t.out.Close()
t.in.Close()

10
exhibit/termios_bsd.go Normal file
View File

@ -0,0 +1,10 @@
// +build darwin freebsd netbsd openbsd
package exhibit
import (
"syscall"
)
const ioctlReadTermios = syscall.TIOCGETA
const ioctlWriteTermios = syscall.TIOCSETA

10
exhibit/termios_linux.go Normal file
View File

@ -0,0 +1,10 @@
// +build linux
package exhibit
import (
"golang.org/x/sys/unix"
)
const ioctlReadTermios = unix.TCGETS
const ioctlWriteTermios = unix.TCSETS