github.com/turingchain2020/turingchain@v1.1.21/common/log/log15/term/terminal_windows.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Based on ssh/terminal:
     6  // Copyright 2011 The Go Authors. All rights reserved.
     7  // Use of this source code is governed by a BSD-style
     8  // license that can be found in the LICENSE file.
     9  
    10  // +build windows
    11  
    12  package term
    13  
    14  import (
    15  	"syscall"
    16  	"unsafe"
    17  )
    18  
    19  var kernel32 = syscall.NewLazyDLL("kernel32.dll")
    20  
    21  var (
    22  	procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
    23  )
    24  
    25  // IsTty returns true if the given file descriptor is a terminal.
    26  func IsTty(fd uintptr) bool {
    27  	var st uint32
    28  	r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0)
    29  	return r != 0 && e == 0
    30  }