Prevent hang if stderr is tty but stdout is not

Previously, the rich TUI would be enabled if either stderr or stdout is
a TTY, but this could cause syft to hang if stderr was a TTY and stdout
was not, as in some cases of redirection.

Signed-off-by: Will Murphy <will.murphy@anchore.com>
This commit is contained in:
Will Murphy 2023-07-29 13:36:27 -04:00
parent 3aae316456
commit 4fb9970481

View File

@ -21,7 +21,7 @@ import (
func Select(verbose, quiet bool) (uis []clio.UI) { func Select(verbose, quiet bool) (uis []clio.UI) {
isStdoutATty := term.IsTerminal(int(os.Stdout.Fd())) isStdoutATty := term.IsTerminal(int(os.Stdout.Fd()))
isStderrATty := term.IsTerminal(int(os.Stderr.Fd())) isStderrATty := term.IsTerminal(int(os.Stderr.Fd()))
notATerminal := !isStderrATty && !isStdoutATty notATerminal := !isStderrATty || !isStdoutATty
switch { switch {
case runtime.GOOS == "windows" || verbose || quiet || notATerminal || !isStderrATty: case runtime.GOOS == "windows" || verbose || quiet || notATerminal || !isStderrATty: