...

Source file src/github.com/moby/term/windows/console.go

Documentation: github.com/moby/term/windows

     1  //go:build windows
     2  // +build windows
     3  
     4  package windowsconsole
     5  
     6  import (
     7  	"os"
     8  
     9  	"golang.org/x/sys/windows"
    10  )
    11  
    12  // GetHandleInfo returns file descriptor and bool indicating whether the file is a console.
    13  func GetHandleInfo(in interface{}) (uintptr, bool) {
    14  	switch t := in.(type) {
    15  	case *ansiReader:
    16  		return t.Fd(), true
    17  	case *ansiWriter:
    18  		return t.Fd(), true
    19  	}
    20  
    21  	var inFd uintptr
    22  	var isTerminal bool
    23  
    24  	if file, ok := in.(*os.File); ok {
    25  		inFd = file.Fd()
    26  		isTerminal = isConsole(inFd)
    27  	}
    28  	return inFd, isTerminal
    29  }
    30  
    31  // IsConsole returns true if the given file descriptor is a Windows Console.
    32  // The code assumes that GetConsoleMode will return an error for file descriptors that are not a console.
    33  //
    34  // Deprecated: use [windows.GetConsoleMode] or [golang.org/x/term.IsTerminal].
    35  func IsConsole(fd uintptr) bool {
    36  	return isConsole(fd)
    37  }
    38  
    39  func isConsole(fd uintptr) bool {
    40  	var mode uint32
    41  	err := windows.GetConsoleMode(windows.Handle(fd), &mode)
    42  	return err == nil
    43  }
    44  

View as plain text