miqt-docker: conditionally use -it if parent was a tty

This commit is contained in:
mappu 2025-04-26 18:39:38 +12:00
parent 69190ece2c
commit b3d5f541f0
3 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,24 @@
//+build linux
//go:build linux
package main
import (
"os"
"syscall"
"unsafe"
)
func isatty() bool {
fd := os.Stdout.Fd()
req := syscall.TCGETS
termios := syscall.Termios{}
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(unsafe.Pointer(&termios)))
if errno != 0 {
return false
}
// Successfully got Termios info = stdout is a tty
return true
}

View File

@ -0,0 +1,8 @@
//+build !linux
//go:build !linux
package main
func isatty() bool {
return true
}

View File

@ -115,7 +115,11 @@ func main() {
// Container match found - safe to run our command
fullCommand := []string{"run", "-it"}
fullCommand := []string{"run"}
if isatty() {
fullCommand = append(fullCommand, "-it")
}
if runtime.GOOS != "windows" {
userinfo, err := user.Current()