Skip to content

Commit

Permalink
Deprecate IsConsole
Browse files Browse the repository at this point in the history
This removes the github.com/Azure/go-ansiterm/winterm dependency
from the windowsconsole package.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed May 7, 2020
1 parent 129dac9 commit dfd17f9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions windows/console.go
Expand Up @@ -4,8 +4,7 @@ package windowsconsole

import (
"os"

"github.com/Azure/go-ansiterm/winterm"
"syscall"
)

// GetHandleInfo returns file descriptor and bool indicating whether the file is a console.
Expand All @@ -22,14 +21,18 @@ func GetHandleInfo(in interface{}) (uintptr, bool) {

if file, ok := in.(*os.File); ok {
inFd = file.Fd()
isTerminal = IsConsole(inFd)
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 {
_, e := winterm.GetConsoleMode(fd)
return e == nil
// Deprecated: use syscall.GetConsoleMode(), golang.org/x/sys/windows.GetConsoleMode(), or golang.org/x/crypto/ssh/terminal.IsTerminal()
var IsConsole = isConsole

func isConsole(fd uintptr) bool {
var mode uint32
err := syscall.GetConsoleMode(syscall.Handle(fd), &mode)
return err == nil
}

0 comments on commit dfd17f9

Please sign in to comment.