fix: treat zero-sized ptys as non-interactive

This commit is contained in:
2026-08-17 19:11:55 +04:00
parent d68c557dd3
commit e13eb9b8a8
2 changed files with 14 additions and 3 deletions
+1 -2
View File
@@ -17,7 +17,6 @@ import (
"charm.land/glamour/v2" "charm.land/glamour/v2"
"charm.land/glamour/v2/styles" "charm.land/glamour/v2/styles"
"charm.land/lipgloss/v2" "charm.land/lipgloss/v2"
"github.com/charmbracelet/x/term"
"go.aykhans.me/sarin/internal/sarin" "go.aykhans.me/sarin/internal/sarin"
"go.aykhans.me/sarin/internal/script" "go.aykhans.me/sarin/internal/script"
"go.aykhans.me/sarin/internal/types" "go.aykhans.me/sarin/internal/types"
@@ -254,7 +253,7 @@ func (config Config) Print() bool {
} }
// Pipe mode: output raw content directly // Pipe mode: output raw content directly
if !term.IsTerminal(os.Stdout.Fd()) { if !sarin.IsInteractiveTerminal(os.Stdout.Fd()) {
fmt.Println(string(configYAML)) fmt.Println(string(configYAML))
os.Exit(0) os.Exit(0)
} }
+13 -1
View File
@@ -51,6 +51,18 @@ func SplitLogLevels(levels string) []string {
return out return out
} }
// IsInteractiveTerminal reports whether fd is a terminal that can actually be
// drawn on. A pty reports as a terminal even while its size is still zero, and
// Bubble Tea paints into a width x height cell buffer, so a zero dimension
// renders nothing at all.
func IsInteractiveTerminal(fd uintptr) bool {
if !term.IsTerminal(fd) {
return false
}
width, height, err := term.GetSize(fd)
return err == nil && width > 0 && height > 0
}
// respLogger logs a single completed response. // respLogger logs a single completed response.
type respLogger func(duration time.Duration, resp *fasthttp.Response) type respLogger func(duration time.Duration, resp *fasthttp.Response)
@@ -302,7 +314,7 @@ func (s sarin) Start(ctx context.Context, stopCtrl *StopController) {
totalRequests = *s.totalRequests totalRequests = *s.totalRequests
} }
onTerminal := term.IsTerminal(os.Stdout.Fd()) onTerminal := IsInteractiveTerminal(os.Stdout.Fd())
// The progress bar needs an interactive terminal to render. // The progress bar needs an interactive terminal to render.
showProgressBar := s.showProgress && onTerminal showProgressBar := s.showProgress && onTerminal
// The bubbletea TUI hosts the bar and/or the live log box, so it runs whenever // The bubbletea TUI hosts the bar and/or the live log box, so it runs whenever