forked from mattn/go-tty
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tty_plan9.go
69 lines (56 loc) · 1.08 KB
/
tty_plan9.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package tty
import (
"bufio"
"os"
"syscall"
"errors"
)
type TTY struct {
in *os.File
bin *bufio.Reader
out *os.File
}
func open() (*TTY, error) {
tty := new(TTY)
in, err := os.Open("/dev/cons")
if err != nil {
return nil, err
}
tty.in = in
tty.bin = bufio.NewReader(in)
out, err := os.OpenFile("/dev/cons", syscall.O_WRONLY, 0)
if err != nil {
return nil, err
}
tty.out = out
return tty, nil
}
func (tty *TTY) buffered() bool {
return tty.bin.Buffered() > 0
}
func (tty *TTY) readRune() (rune, error) {
r, _, err := tty.bin.ReadRune()
return r, err
}
func (tty *TTY) close() (err error) {
if err2 := tty.in.Close(); err2 != nil {
err = err2
}
if err2 := tty.out.Close(); err2 != nil {
err = err2
}
return
}
func (tty *TTY) size() (int, int, error) {
return 80, 24, nil
}
func (tty *TTY) sizePixel() (int, int, int, int, error) {
x, y, _ := tty.size()
return x, y, -1, -1, errors.New("no implemented method for querying size in pixels on Plan 9")
}
func (tty *TTY) input() *os.File {
return tty.in
}
func (tty *TTY) output() *os.File {
return tty.out
}