mirror of
https://github.com/mappu/miqt.git
synced 2025-05-28 14:00:25 +00:00
miqt-docker: conditionally use -it if parent was a tty
This commit is contained in:
parent
69190ece2c
commit
b3d5f541f0
24
cmd/miqt-docker/isatty_linux.go
Normal file
24
cmd/miqt-docker/isatty_linux.go
Normal 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
|
||||
}
|
8
cmd/miqt-docker/isatty_other.go
Normal file
8
cmd/miqt-docker/isatty_other.go
Normal file
@ -0,0 +1,8 @@
|
||||
//+build !linux
|
||||
//go:build !linux
|
||||
|
||||
package main
|
||||
|
||||
func isatty() bool {
|
||||
return true
|
||||
}
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user