Merge pull request #10 from thaJeztah/deprecate_isconsole
Deprecate IsConsole in favor of "golang.org/x/.." implementations
Brian Goff authored 4 years ago
GitHub committed 4 years ago
4 | 4 | import ( |
5 | 5 | "os" |
6 | 6 | |
7 | "github.com/Azure/go-ansiterm/winterm" | |
7 | "golang.org/x/sys/windows" | |
8 | 8 | ) |
9 | 9 | |
10 | 10 | // GetHandleInfo returns file descriptor and bool indicating whether the file is a console. |
21 | 21 | |
22 | 22 | if file, ok := in.(*os.File); ok { |
23 | 23 | inFd = file.Fd() |
24 | isTerminal = IsConsole(inFd) | |
24 | isTerminal = isConsole(inFd) | |
25 | 25 | } |
26 | 26 | return inFd, isTerminal |
27 | 27 | } |
28 | 28 | |
29 | 29 | // IsConsole returns true if the given file descriptor is a Windows Console. |
30 | 30 | // The code assumes that GetConsoleMode will return an error for file descriptors that are not a console. |
31 | func IsConsole(fd uintptr) bool { | |
32 | _, e := winterm.GetConsoleMode(fd) | |
33 | return e == nil | |
31 | // Deprecated: use golang.org/x/sys/windows.GetConsoleMode() or golang.org/x/crypto/ssh/terminal.IsTerminal() | |
32 | var IsConsole = isConsole | |
33 | ||
34 | func isConsole(fd uintptr) bool { | |
35 | var mode uint32 | |
36 | err := windows.GetConsoleMode(windows.Handle(fd), &mode) | |
37 | return err == nil | |
34 | 38 | } |