-
Notifications
You must be signed in to change notification settings - Fork 4
/
tty_windows.go
64 lines (51 loc) · 1.08 KB
/
tty_windows.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
//go:build windows
// +build windows
package main
import (
"fmt"
"github.com/gdamore/tcell/v2"
"os"
)
// stdIoTty is an implementation of the Tty API based upon stdin/stdout.
type stdIoTty struct {
in *os.File
out *os.File
}
func (tty *stdIoTty) Read(b []byte) (int, error) {
return tty.in.Read(b)
}
func (tty *stdIoTty) Write(b []byte) (int, error) {
return tty.out.Write(b)
}
func (tty *stdIoTty) Close() error {
return nil
}
func (tty *stdIoTty) Start() error {
tty.in = os.Stdin
tty.out = os.Stdout
return nil
}
func (tty *stdIoTty) Drain() error {
return nil
}
func (tty *stdIoTty) Stop() error {
return nil
}
func (tty *stdIoTty) WindowSize() (tcell.WindowSize, error) {
return tcell.WindowSize{}, fmt.Errorf("not implemented")
}
func (tty *stdIoTty) NotifyResize(cb func()) {
}
// NewStdioTty opens a tty using standard input/output.
func NewStdIoTty() (tcell.Tty, error) {
tty := &stdIoTty{
in: os.Stdin,
out: os.Stdout,
}
return tty, nil
}
func opentty() (tty tcell.Tty, err error) {
debugLog.Println("Using stdio tty")
tty, err = NewStdIoTty()
return
}