diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/mattn/go-isatty/isatty_windows.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/mattn/go-isatty/isatty_windows.go')
-rw-r--r-- | vendor/github.com/mattn/go-isatty/isatty_windows.go | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/vendor/github.com/mattn/go-isatty/isatty_windows.go b/vendor/github.com/mattn/go-isatty/isatty_windows.go index 83c398b..af51cbc 100644 --- a/vendor/github.com/mattn/go-isatty/isatty_windows.go +++ b/vendor/github.com/mattn/go-isatty/isatty_windows.go | |||
@@ -4,12 +4,30 @@ | |||
4 | package isatty | 4 | package isatty |
5 | 5 | ||
6 | import ( | 6 | import ( |
7 | "strings" | ||
7 | "syscall" | 8 | "syscall" |
9 | "unicode/utf16" | ||
8 | "unsafe" | 10 | "unsafe" |
9 | ) | 11 | ) |
10 | 12 | ||
11 | var kernel32 = syscall.NewLazyDLL("kernel32.dll") | 13 | const ( |
12 | var procGetConsoleMode = kernel32.NewProc("GetConsoleMode") | 14 | fileNameInfo uintptr = 2 |
15 | fileTypePipe = 3 | ||
16 | ) | ||
17 | |||
18 | var ( | ||
19 | kernel32 = syscall.NewLazyDLL("kernel32.dll") | ||
20 | procGetConsoleMode = kernel32.NewProc("GetConsoleMode") | ||
21 | procGetFileInformationByHandleEx = kernel32.NewProc("GetFileInformationByHandleEx") | ||
22 | procGetFileType = kernel32.NewProc("GetFileType") | ||
23 | ) | ||
24 | |||
25 | func init() { | ||
26 | // Check if GetFileInformationByHandleEx is available. | ||
27 | if procGetFileInformationByHandleEx.Find() != nil { | ||
28 | procGetFileInformationByHandleEx = nil | ||
29 | } | ||
30 | } | ||
13 | 31 | ||
14 | // IsTerminal return true if the file descriptor is terminal. | 32 | // IsTerminal return true if the file descriptor is terminal. |
15 | func IsTerminal(fd uintptr) bool { | 33 | func IsTerminal(fd uintptr) bool { |
@@ -17,3 +35,60 @@ func IsTerminal(fd uintptr) bool { | |||
17 | r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0) | 35 | r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0) |
18 | return r != 0 && e == 0 | 36 | return r != 0 && e == 0 |
19 | } | 37 | } |
38 | |||
39 | // Check pipe name is used for cygwin/msys2 pty. | ||
40 | // Cygwin/MSYS2 PTY has a name like: | ||
41 | // \{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master | ||
42 | func isCygwinPipeName(name string) bool { | ||
43 | token := strings.Split(name, "-") | ||
44 | if len(token) < 5 { | ||
45 | return false | ||
46 | } | ||
47 | |||
48 | if token[0] != `\msys` && token[0] != `\cygwin` { | ||
49 | return false | ||
50 | } | ||
51 | |||
52 | if token[1] == "" { | ||
53 | return false | ||
54 | } | ||
55 | |||
56 | if !strings.HasPrefix(token[2], "pty") { | ||
57 | return false | ||
58 | } | ||
59 | |||
60 | if token[3] != `from` && token[3] != `to` { | ||
61 | return false | ||
62 | } | ||
63 | |||
64 | if token[4] != "master" { | ||
65 | return false | ||
66 | } | ||
67 | |||
68 | return true | ||
69 | } | ||
70 | |||
71 | // IsCygwinTerminal() return true if the file descriptor is a cygwin or msys2 | ||
72 | // terminal. | ||
73 | func IsCygwinTerminal(fd uintptr) bool { | ||
74 | if procGetFileInformationByHandleEx == nil { | ||
75 | return false | ||
76 | } | ||
77 | |||
78 | // Cygwin/msys's pty is a pipe. | ||
79 | ft, _, e := syscall.Syscall(procGetFileType.Addr(), 1, fd, 0, 0) | ||
80 | if ft != fileTypePipe || e != 0 { | ||
81 | return false | ||
82 | } | ||
83 | |||
84 | var buf [2 + syscall.MAX_PATH]uint16 | ||
85 | r, _, e := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), | ||
86 | 4, fd, fileNameInfo, uintptr(unsafe.Pointer(&buf)), | ||
87 | uintptr(len(buf)*2), 0, 0) | ||
88 | if r == 0 || e != 0 { | ||
89 | return false | ||
90 | } | ||
91 | |||
92 | l := *(*uint32)(unsafe.Pointer(&buf)) | ||
93 | return isCygwinPipeName(string(utf16.Decode(buf[2 : 2+l/2]))) | ||
94 | } | ||