-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with tui interactions for vex discovery
Signed-off-by: Alex Goodman <[email protected]>
- Loading branch information
Showing
5 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ui | ||
|
||
import ( | ||
"fmt" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/dustin/go-humanize" | ||
"github.com/wagoodman/go-partybus" | ||
"github.com/wagoodman/go-progress" | ||
|
||
"github.com/anchore/bubbly/bubbles/taskprogress" | ||
"github.com/anchore/grype/grype/event/parsers" | ||
"github.com/anchore/grype/internal/log" | ||
) | ||
|
||
type vexDocumentDiscoveryStager struct { | ||
prog progress.StagedProgressable | ||
} | ||
|
||
func (s vexDocumentDiscoveryStager) Stage() string { | ||
stage := s.prog.Stage() | ||
if stage == "downloading" { | ||
// note: since validation is baked into the download progress there is no visibility into this stage. | ||
// for that reason we report "validating" on the last byte being downloaded (which tends to be the longest | ||
// since go-downloader is doing this work). | ||
if s.prog.Current() >= s.prog.Size()-1 { | ||
return "validating" | ||
} | ||
// show intermediate progress of the download | ||
return fmt.Sprintf("%s / %s", humanize.Bytes(uint64(s.prog.Current())), humanize.Bytes(uint64(s.prog.Size()))) | ||
} | ||
return stage | ||
} | ||
|
||
func (m *Handler) handleVexDocumentDiscoveryStarted(e partybus.Event) ([]tea.Model, tea.Cmd) { | ||
prog, err := parsers.ParseVexDocumentDiscoveryStarted(e) | ||
if err != nil { | ||
log.WithFields("error", err).Warn("unable to parse event") | ||
return nil, nil | ||
} | ||
|
||
tsk := m.newTaskProgress( | ||
taskprogress.Title{ | ||
Default: "Search for VEX Documents", | ||
Running: "Searching for VEX Documents", | ||
Success: "Searched for VEX Documents", | ||
}, | ||
taskprogress.WithStagedProgressable(prog), // ignore the static stage provided by the event | ||
taskprogress.WithStager(vexDocumentDiscoveryStager{prog: prog}), | ||
) | ||
|
||
tsk.HideStageOnSuccess = false | ||
|
||
return []tea.Model{tsk}, tsk.Init() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters