Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unix.Ioctl* on BSD systems, deduplicate tscreen_*.go #29

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 0 additions & 121 deletions tscreen_bsd.go

This file was deleted.

67 changes: 27 additions & 40 deletions tscreen_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ package tcell
import (
"os/signal"
"syscall"
"unsafe"

"github.com/zyedidia/poller"

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

type termiosPrivate syscall.Termios
type termiosPrivate struct {
tio *unix.Termios
}

func (t *tScreen) termioInit() error {
var e error
var newtios termiosPrivate
var fd uintptr
var tios uintptr
var ioc uintptr
t.tiosp = &termiosPrivate{}
var raw unix.Termios
var tio *unix.Termios

if t.in, e = poller.Open("/dev/tty", poller.O_RO); e != nil {
goto failed
Expand All @@ -60,29 +60,24 @@ func (t *tScreen) termioInit() error {
goto failed
}

tios = uintptr(unsafe.Pointer(t.tiosp))
ioc = uintptr(syscall.TIOCGETA)
fd = uintptr(t.out.(*poller.FD).Sysfd())
if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 {
e = e1
tio, e = unix.IoctlGetTermios(int(t.out.(*poller.FD).Sysfd()), getTermios)
if e != nil {
goto failed
}

newtios = *t.tiosp
newtios.Iflag &^= syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK |
syscall.ISTRIP | syscall.INLCR | syscall.IGNCR |
syscall.ICRNL | syscall.IXON
newtios.Oflag &^= syscall.OPOST
newtios.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON |
syscall.ISIG | syscall.IEXTEN
newtios.Cflag &^= syscall.CSIZE | syscall.PARENB
newtios.Cflag |= syscall.CS8

tios = uintptr(unsafe.Pointer(&newtios))

ioc = uintptr(syscall.TIOCSETA)
if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 {
e = e1
t.tiosp = &termiosPrivate{tio: tio}

raw = *tio
raw.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP |
unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)
raw.Oflag &^= unix.OPOST
raw.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG |
unix.IEXTEN)
raw.Cflag &^= (unix.CSIZE | unix.PARENB)
raw.Cflag |= unix.CS8

e = unix.IoctlSetTermios(int(t.out.(*poller.FD).Sysfd()), setTermios, &raw)
if e != nil {
goto failed
}

Expand Down Expand Up @@ -110,11 +105,8 @@ func (t *tScreen) termioFini() {

<-t.indoneq

if t.out != nil {
fd := uintptr(t.out.(*poller.FD).Sysfd())
ioc := uintptr(syscall.TIOCSETAF)
tios := uintptr(unsafe.Pointer(t.tiosp))
syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0)
if t.out != nil && t.tiosp != nil {
unix.IoctlSetTermios(int(t.out.(*poller.FD).Sysfd()), flushTermios, t.tiosp.tio)
t.out.(*poller.FD).Close()
}

Expand All @@ -124,16 +116,11 @@ func (t *tScreen) termioFini() {
}

func (t *tScreen) getWinSize() (int, int, error) {

fd := uintptr(t.out.(*poller.FD).Sysfd())
dim := [4]uint16{}
dimp := uintptr(unsafe.Pointer(&dim))
ioc := uintptr(syscall.TIOCGWINSZ)
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL,
fd, ioc, dimp, 0, 0, 0); err != 0 {
wsz, err := unix.IoctlGetWinsize(int(t.out.(*poller.FD).Sysfd()), unix.TIOCGWINSZ)
if err != nil {
return -1, -1, err
}
return int(dim[1]), int(dim[0]), nil
return int(wsz.Col), int(wsz.Row), nil
}

func (t *tScreen) Beep() error {
Expand Down
122 changes: 0 additions & 122 deletions tscreen_solaris.go

This file was deleted.

Loading