mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 16:06:36 +01:00
Split UI from event handling (#448)
* 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>
This commit is contained in:
@@ -8,11 +8,12 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/anchore/syft/internal/ui/components"
|
||||
|
||||
"github.com/anchore/stereoscope/pkg/image/docker"
|
||||
"github.com/dustin/go-humanize"
|
||||
|
||||
stereoEventParsers "github.com/anchore/stereoscope/pkg/event/parsers"
|
||||
"github.com/anchore/syft/internal/ui/common"
|
||||
syftEventParsers "github.com/anchore/syft/syft/event/parsers"
|
||||
"github.com/gookit/color"
|
||||
"github.com/wagoodman/go-partybus"
|
||||
@@ -22,8 +23,8 @@ import (
|
||||
)
|
||||
|
||||
const maxBarWidth = 50
|
||||
const statusSet = common.SpinnerDotSet // SpinnerCircleOutlineSet
|
||||
const completedStatus = "✔" // "●"
|
||||
const statusSet = components.SpinnerDotSet
|
||||
const completedStatus = "✔"
|
||||
const tileFormat = color.Bold
|
||||
const interval = 150 * time.Millisecond
|
||||
|
||||
@@ -41,14 +42,14 @@ var (
|
||||
|
||||
// startProcess is a helper function for providing common elements for long-running UI elements (such as a
|
||||
// progress bar formatter and status spinner)
|
||||
func startProcess() (format.Simple, *common.Spinner) {
|
||||
func startProcess() (format.Simple, *components.Spinner) {
|
||||
width, _ := frame.GetTerminalSize()
|
||||
barWidth := int(0.25 * float64(width))
|
||||
if barWidth > maxBarWidth {
|
||||
barWidth = maxBarWidth
|
||||
}
|
||||
formatter := format.NewSimpleWithTheme(barWidth, format.HeavyNoBarTheme, format.ColorCompleted, format.ColorTodo)
|
||||
spinner := common.NewSpinner(statusSet)
|
||||
spinner := components.NewSpinner(statusSet)
|
||||
|
||||
return formatter, &spinner
|
||||
}
|
||||
@@ -76,7 +77,7 @@ func formatDockerPullPhase(phase docker.PullPhase, inputStr string) string {
|
||||
|
||||
// nolint:funlen
|
||||
// formatDockerImagePullStatus writes the docker image pull status summarized into a single line for the given state.
|
||||
func formatDockerImagePullStatus(pullStatus *docker.PullStatus, spinner *common.Spinner, line *frame.Line) {
|
||||
func formatDockerImagePullStatus(pullStatus *docker.PullStatus, spinner *components.Spinner, line *frame.Line) {
|
||||
var size, current uint64
|
||||
|
||||
title := tileFormat.Sprint("Pulling image")
|
||||
|
||||
Reference in New Issue
Block a user