2015-04-16 17:01:37 -04:00
|
|
|
// +build windows
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package windowsconsole // import "github.com/docker/docker/pkg/term/windows"
|
2015-04-16 17:01:37 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2015-09-03 16:01:56 -04:00
|
|
|
"github.com/Azure/go-ansiterm/winterm"
|
2015-04-16 17:01:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
func IsConsole(fd uintptr) bool {
|
2015-09-03 16:01:56 -04:00
|
|
|
_, e := winterm.GetConsoleMode(fd)
|
2015-04-16 17:01:37 -04:00
|
|
|
return e == nil
|
|
|
|
}
|