| 1 |
// +build darwin |
| 2 |
|
| 3 |
package tcell |
| 4 |
|
| 5 |
// The Darwin system is *almost* a real BSD system, but it suffers from |
| 6 |
// a brain damaged TTY driver. This TTY driver does not actually |
| 7 |
// wake up in poll() or similar calls, which means that we cannot reliably |
| 8 |
// shut down the terminal without resorting to obscene custom C code |
| 9 |
// and a dedicated poller thread. |
| 10 |
// |
| 11 |
// So instead, we do a best effort, and simply try to do the close in the |
| 12 |
// background. Probably this will cause a leak of two goroutines and |
| 13 |
// maybe also the file descriptor, meaning that applications on Darwin |
| 14 |
// can't reinitialize the screen, but that's probably a very rare behavior, |
| 15 |
// and accepting that is the best of some very poor alternative options. |
| 16 |
// |
| 17 |
// Maybe someday Apple will fix there tty driver, but its been broken for |
| 18 |
// a long time (probably forever) so holding one's breath is contraindicated. |
| 19 |
// |
| 20 |
// NOTE: In this fork of tcell, we fix this issue by using the library |
| 21 |
// zyedidia/poller to properly interface with the tty such that when we |
| 22 |
// close it, it actually closes |
| 23 |
|
| 24 |
import ( |
| 25 |
"io" |
| 26 |
|
| 27 |
"github.com/zyedidia/poller" |
| 28 |
) |
| 29 |
|
| 30 |
func openTty() (io.Reader, io.Writer, error) { |
| 31 |
var out io.Writer |
| 32 |
in, err := poller.Open("/dev/tty", poller.O_RO) |
| 33 |
if err == nil { |
| 34 |
out, err = poller.Open("/dev/tty", poller.O_WO) |
| 35 |
} |
| 36 |
|
| 37 |
return in, out, err |
| 38 |
} |
| 39 |
|
| 40 |
func closeTty(f interface{}) { |
| 41 |
f.(*poller.FD).Close() |
| 42 |
} |
| 43 |
|
| 44 |
func (t *tScreen) fd() int { |
| 45 |
return t.out.(*poller.FD).Sysfd() |
| 46 |
} |