Skip to content

Commit

Permalink
Deprecate IsConsole in favor of "golang.org/x/.." implementations
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, and replaces it with
`golang.org/x/sys/windows`.

Marking this function as deprecated, given that this functionality
is already provided by the "standard" `golang.org/x/..` packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed May 7, 2020
1 parent 129dac9 commit 57a2131
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions windows/console.go
Expand Up @@ -5,7 +5,7 @@ package windowsconsole
import (
"os"

"github.com/Azure/go-ansiterm/winterm"
"golang.org/x/sys/windows"
)

// GetHandleInfo returns file descriptor and bool indicating whether the file is a console.
Expand All @@ -22,14 +22,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 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 := windows.GetConsoleMode(windows.Handle(fd), &mode)
return err == nil
}

0 comments on commit 57a2131

Please sign in to comment.