github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/pkg/term/windows/console.go (about)

     1  // +build windows
     2  
     3  package windows
     4  
     5  import (
     6  	"os"
     7  
     8  	"github.com/Azure/go-ansiterm/winterm"
     9  )
    10  
    11  // GetHandleInfo returns file descriptor and bool indicating whether the file is a console.
    12  func GetHandleInfo(in interface{}) (uintptr, bool) {
    13  	switch t := in.(type) {
    14  	case *ansiReader:
    15  		return t.Fd(), true
    16  	case *ansiWriter:
    17  		return t.Fd(), true
    18  	}
    19  
    20  	var inFd uintptr
    21  	var isTerminal bool
    22  
    23  	if file, ok := in.(*os.File); ok {
    24  		inFd = file.Fd()
    25  		isTerminal = IsConsole(inFd)
    26  	}
    27  	return inFd, isTerminal
    28  }
    29  
    30  // IsConsole returns true if the given file descriptor is a Windows Console.
    31  // The code assumes that GetConsoleMode will return an error for file descriptors that are not a console.
    32  func IsConsole(fd uintptr) bool {
    33  	_, e := winterm.GetConsoleMode(fd)
    34  	return e == nil
    35  }