File: tty_plan9.go

package info (click to toggle)
golang-github-mattn-go-tty 0.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 128 kB
  • sloc: makefile: 3
file content (69 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (2)
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"
	"errors"
	"os"
	"syscall"
)

type TTY struct {
	in  *os.File
	bin *bufio.Reader
	out *os.File
}

func open(path string) (*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
}