diff --git a/pkg/shell/tty.go b/pkg/shell/tty.go index d433369f..f320130c 100644 --- a/pkg/shell/tty.go +++ b/pkg/shell/tty.go @@ -1,4 +1,4 @@ -//go:build !unix +//go:build !unix && !windows package shell diff --git a/pkg/shell/tty_windows.go b/pkg/shell/tty_windows.go new file mode 100644 index 00000000..6216e742 --- /dev/null +++ b/pkg/shell/tty_windows.go @@ -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 +}