-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtty_windows.go
More file actions
49 lines (35 loc) · 675 Bytes
/
Copy pathtty_windows.go
File metadata and controls
49 lines (35 loc) · 675 Bytes
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
//go:build windows
// +build windows
package keyboard
import (
"fmt"
"os"
"syscall"
"github.com/containerd/console"
)
var windowsStdin *os.File
func restoreInput() error {
if windowsStdin != nil {
os.Stdin = windowsStdin
}
return nil
}
func initInput() error {
windowsStdin = os.Stdin
os.Stdin = stdin
var mode uint32
err := syscall.GetConsoleMode(syscall.Stdin, &mode)
if err != nil {
mocking = true
return nil
}
con = console.Current()
return nil
}
func openInputTTY() (*os.File, error) {
f, err := os.OpenFile("CONIN$", os.O_RDWR, 0644)
if err != nil {
return nil, fmt.Errorf("failed to open stdin TTY: %w", err)
}
return f, nil
}