fix(tui): skip the progress display when running as a background job

This commit is contained in:
aykhans committed 2026-10-20 13:30:50 +04:00
1 parent f84644c688
commit 00c7bf4afb
5 files changed
+34 -2

No files matched your search

+1 -1
View File
@@ -16,6 +16,7 @@ require (
go.aykhans.me/utils v1.0.7
go.yaml.in/yaml/v4 v4.0.0-rc.6
golang.org/x/net v0.60.0
golang.org/x/sys v0.49.0
)
require (
@@ -48,6 +49,5 @@ require (
github.com/yuin/goldmark v1.8.6 // indirect
github.com/yuin/goldmark-emoji v1.0.6 // indirect
golang.org/x/sync v0.24.0 // indirect
golang.org/x/sys v0.49.0 // indirect
golang.org/x/text v0.42.0 // indirect
)
+13
View File
@@ -0,0 +1,13 @@
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
package sarin
import "golang.org/x/sys/unix"
// isForeground is the same check as on linux, see foreground_linux.go.
func isForeground(fd uintptr) bool {
v, err := unix.IoctlGetInt(int(fd), unix.TIOCGPGRP)
// The kernel writes a 32 bit pid_t, which lands in the high half of a 64 bit big-endian int.
pgrp := int(uint32(int64(v)) | uint32(int64(v)>>32))
return err != nil || pgrp == unix.Getpgrp()
}
+10
View File
@@ -0,0 +1,10 @@
package sarin
import "golang.org/x/sys/unix"
// isForeground reports false only for a background job, which raw mode would stop with SIGTTOU.
func isForeground(fd uintptr) bool {
// pid_t is 32 bits, a 32 bit read keeps big-endian right.
pgrp, err := unix.IoctlGetUint32(int(fd), unix.TIOCGPGRP)
return err != nil || int(pgrp) == unix.Getpgrp()
}
+8
View File
@@ -0,0 +1,8 @@
//go:build !linux && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd
package sarin
// isForeground has no background job check on this platform.
func isForeground(uintptr) bool {
return true
}
+2 -1
View File
@@ -337,7 +337,8 @@ func (s sarin) Start(stopCtrl *StopController) {
totalRequests = *s.totalRequests
}
onTerminal := IsInteractiveTerminal(os.Stdout.Fd())
// A background job would get SIGTTOU from the TUI, so it runs without one.
onTerminal := IsInteractiveTerminal(os.Stdout.Fd()) && isForeground(os.Stdout.Fd()) && isForeground(os.Stdin.Fd())
// The progress bar needs an interactive terminal to render.
showProgressBar := s.showProgress && onTerminal
// The bubbletea TUI hosts the bar and/or the live log box, so it runs whenever