implement ui handle waiter (#1930)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman
2023-07-12 13:14:54 -04:00
committed by GitHub
parent 38efe4ec5f
commit 4fc17edd14
4 changed files with 37 additions and 17 deletions
+10 -2
View File
@@ -12,7 +12,11 @@ import (
syftEvent "github.com/anchore/syft/syft/event"
)
var _ bubbly.EventHandler = (*Handler)(nil)
var _ interface {
bubbly.EventHandler
bubbly.MessageListener
bubbly.HandleWaiter
} = (*Handler)(nil)
type HandlerConfig struct {
TitleWidth int
@@ -61,8 +65,12 @@ func New(cfg HandlerConfig) *Handler {
return h
}
func (m *Handler) Update(msg tea.Msg) {
func (m *Handler) OnMessage(msg tea.Msg) {
if msg, ok := msg.(tea.WindowSizeMsg); ok {
m.WindowSize = msg
}
}
func (m *Handler) Wait() {
m.Running.Wait()
}
+1 -1
View File
@@ -118,7 +118,7 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// that is the responsibility of the frame object on this UI object. The handler is a factory of models
// which the frame is responsible for the lifecycle of. This update allows for injecting the initial state
// of the world when creating those models.
m.handler.Update(msg)
m.handler.OnMessage(msg)
switch msg := msg.(type) {
case tea.KeyMsg: