mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
* split UI from event handling Signed-off-by: Alex Goodman <wagoodman@gmail.com> * add event loop tests Signed-off-by: Alex Goodman <wagoodman@gmail.com> * use stereoscope cleanup function during signal handling Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * correct error wrapping in packages cmd Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * migrate ui event handlers to ui package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * clarify command worker input var + remove dead comments Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
30 lines
707 B
Go
30 lines
707 B
Go
package ui
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
)
|
|
|
|
// TODO: build tags to exclude options from windows
|
|
|
|
// 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).
|
|
func Select(verbose, quiet bool) UI {
|
|
var ui UI
|
|
|
|
isStdoutATty := terminal.IsTerminal(int(os.Stdout.Fd()))
|
|
isStderrATty := terminal.IsTerminal(int(os.Stderr.Fd()))
|
|
notATerminal := !isStderrATty && !isStdoutATty
|
|
|
|
switch {
|
|
case runtime.GOOS == "windows" || verbose || quiet || notATerminal || !isStderrATty:
|
|
ui = NewLoggerUI()
|
|
default:
|
|
ui = NewEphemeralTerminalUI()
|
|
}
|
|
|
|
return ui
|
|
}
|