feat(shell): add Windows support for TTY detection

This commit is contained in:
Sergey Krashevich
2024-05-28 10:16:48 +03:00
parent 791239be12
commit cc74504ed8
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !unix
//go:build !unix && !windows
package shell
+19
View File
@@ -0,0 +1,19 @@
//go:build windows
package shell
import (
"syscall"
"unsafe"
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
)
func IsInteractive(fd uintptr) bool {
var st uint32
r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0)
return r != 0 && e == 0
}