func IsTerminal(fd uintptr) bool {
	return windows.IsConsole(fd)
}
IsTerminal returns true if the given file descriptor is a terminal.
package term
import (
	"io"
	"os"
	"os/signal"
	"syscall"
	"github.com/Azure/go-ansiterm/winterm"
	"github.com/docker/docker/pkg/system"
	"github.com/docker/docker/pkg/term/windows"
)
type State struct {
	inMode, outMode     uint32
	inHandle, outHandle syscall.Handle
}
type Winsize struct {
	Height uint16
	Width  uint16
	x      uint16
	y      uint16
}
const (
	enableVirtualTerminalInput      = 0x0200
	enableVirtualTerminalProcessing = 0x0004
)
var usingNativeConsole bool
func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
	switch {
	case os.Getenv("ConEmuANSI") == "ON":
		return windows.ConEmuStreams()
	case os.Getenv("MSYSTEM") != "":
		return windows.ConsoleStreams()
	default:
		if useNativeConsole() {
			usingNativeConsole = true
			return os.Stdin, os.Stdout, os.Stderr
		}
		return windows.ConsoleStreams()
	}
}
func useNativeConsole() bool {
	osv, err := system.GetOSVersion()
	if err != nil {
		return false
	}
	if osv.MajorVersion < 10 {
		return false
	}
	if osv.Build < 10578 {
		return false
	}
	state, err := getNativeConsole()
	if err != nil {
		return false
	}
	if nil != probeNativeConsole(state) {
		return false
	}
	if e := os.Getenv("USE_NATIVE_CONSOLE"); e != "" {
		if e == "1" {
			return true
		}
		return false
	}
	return false
}
func getNativeConsole() (State, error) {
	var (
		err   error
		state State
	)
	if state.outHandle, err = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE); err != nil {
		return state, err
	}
	if err = syscall.GetConsoleMode(state.outHandle, &state.outMode); err != nil {
		return state, err
	}
	if state.inHandle, err = syscall.GetStdHandle(syscall.STD_INPUT_HANDLE); err != nil {
		return state, err
	}
	if err = syscall.GetConsoleMode(state.inHandle, &state.inMode); err != nil {
		return state, err
	}
	return state, nil
}
func probeNativeConsole(state State) error {
	if err := winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode|enableVirtualTerminalProcessing); err != nil {
		return err
	}
	defer winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode)
	if err := winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode|enableVirtualTerminalInput); err != nil {
		return err
	}
	defer winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode)
	return nil
}
func enableNativeConsole(state State) error {
	if err := winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode|enableVirtualTerminalProcessing); err != nil {
		return err
	}
	if err := winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode|enableVirtualTerminalInput); err != nil {
		winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode)  
		return err
	}
	return nil
}
func disableNativeConsole(state *State) error {
	errout := winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode)
	errin := winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode)
	if errout != nil {
		return errout
	}
	if errin != nil {
		return errin
	}
	return nil
}
func GetFdInfo(in interface{}) (uintptr, bool) {
	return windows.GetHandleInfo(in)
}
func GetWinsize(fd uintptr) (*Winsize, error) {
	info, err := winterm.GetConsoleScreenBufferInfo(fd)
	if err != nil {
		return nil, err
	}
	winsize := &Winsize{
		Width:  uint16(info.Window.Right - info.Window.Left + 1),
		Height: uint16(info.Window.Bottom - info.Window.Top + 1),
		x:      0,
		y:      0}
	return winsize, nil
}