-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tty.go
43 lines (35 loc) · 841 Bytes
/
tty.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
package dummytty
import (
"io"
"strings"
"github.com/srlehn/termimg/internal"
"github.com/srlehn/termimg/internal/errors"
"github.com/srlehn/termimg/term"
)
type TTYDummy struct {
rdr *strings.Reader
fileName string
}
var _ term.TTY = (*TTYDummy)(nil)
func New(buf string) (*TTYDummy, error) {
rdr := strings.NewReader(buf)
return &TTYDummy{
rdr: rdr,
fileName: internal.DefaultTTYDevice(),
}, nil
}
func (t *TTYDummy) Write(b []byte) (n int, err error) { return io.Discard.Write(b) }
func (t *TTYDummy) Read(p []byte) (n int, err error) {
if t == nil || t.rdr == nil {
return 0, errors.NilReceiver()
}
return t.rdr.Read(p)
}
func (t *TTYDummy) TTYDevName() string {
if t == nil {
return internal.DefaultTTYDevice()
}
return t.fileName
}
// Close ...
func (t *TTYDummy) Close() error { return nil }