Codebase list golang-github-moby-term / a2ece12
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
1 changed file(s) with 9 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
44 import (
55 "os"
66
7 "github.com/Azure/go-ansiterm/winterm"
7 "golang.org/x/sys/windows"
88 )
99
1010 // GetHandleInfo returns file descriptor and bool indicating whether the file is a console.
2121
2222 if file, ok := in.(*os.File); ok {
2323 inFd = file.Fd()
24 isTerminal = IsConsole(inFd)
24 isTerminal = isConsole(inFd)
2525 }
2626 return inFd, isTerminal
2727 }
2828
2929 // IsConsole returns true if the given file descriptor is a Windows Console.
3030 // 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
3438 }