mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
32 lines
1019 B
Go
32 lines
1019 B
Go
//go:build linux || darwin || netbsd
|
|
// +build linux darwin netbsd
|
|
|
|
package ui
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
// Select is responsible for determining the specific UI function given select user option, the current platform
|
|
// config values, and environment status (such as a TTY being present). The first UI in the returned slice of UIs
|
|
// is intended to be used and the UIs that follow are meant to be attempted only in a fallback posture when there
|
|
// are environmental problems (e.g. cannot write to the terminal). A writer is provided to capture the output of
|
|
// the final SBOM report.
|
|
func Select(verbose, quiet bool) (uis []UI) {
|
|
isStdoutATty := term.IsTerminal(int(os.Stdout.Fd()))
|
|
isStderrATty := term.IsTerminal(int(os.Stderr.Fd()))
|
|
notATerminal := !isStderrATty && !isStdoutATty
|
|
|
|
switch {
|
|
case runtime.GOOS == "windows" || verbose || quiet || notATerminal || !isStderrATty:
|
|
uis = append(uis, NewLoggerUI())
|
|
default:
|
|
uis = append(uis, NewEphemeralTerminalUI())
|
|
}
|
|
|
|
return uis
|
|
}
|