mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
e8381db778
* Update Kubernetes to v1.21.0 * Update to golang v1.16.2 * Update dependent modules to track with upstream * Switch to upstream flannel * Track changes to upstream cloud-controller-manager and FeatureGates Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
40 lines
938 B
Go
40 lines
938 B
Go
// +build windows
|
|
|
|
package windowsconsole
|
|
|
|
import (
|
|
"os"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// GetHandleInfo returns file descriptor and bool indicating whether the file is a console.
|
|
func GetHandleInfo(in interface{}) (uintptr, bool) {
|
|
switch t := in.(type) {
|
|
case *ansiReader:
|
|
return t.Fd(), true
|
|
case *ansiWriter:
|
|
return t.Fd(), true
|
|
}
|
|
|
|
var inFd uintptr
|
|
var isTerminal bool
|
|
|
|
if file, ok := in.(*os.File); ok {
|
|
inFd = file.Fd()
|
|
isTerminal = isConsole(inFd)
|
|
}
|
|
return inFd, isTerminal
|
|
}
|
|
|
|
// IsConsole returns true if the given file descriptor is a Windows Console.
|
|
// The code assumes that GetConsoleMode will return an error for file descriptors that are not a console.
|
|
// Deprecated: use golang.org/x/sys/windows.GetConsoleMode() or golang.org/x/term.IsTerminal()
|
|
var IsConsole = isConsole
|
|
|
|
func isConsole(fd uintptr) bool {
|
|
var mode uint32
|
|
err := windows.GetConsoleMode(windows.Handle(fd), &mode)
|
|
return err == nil
|
|
}
|