github.com/kastenhq/syft@v0.0.0-20230821225854-0710af25cdbe/syft/event/monitor/cataloger_task.go (about) 1 package monitor 2 3 import ( 4 "github.com/wagoodman/go-partybus" 5 "github.com/wagoodman/go-progress" 6 7 "github.com/kastenhq/syft/internal/bus" 8 "github.com/kastenhq/syft/syft/event" 9 ) 10 11 // TODO: this should be refactored to support read-only/write-only access using idioms of the progress lib 12 13 type CatalogerTask struct { 14 prog *progress.Manual 15 // Title 16 Title string 17 // TitleOnCompletion a string to use as title when completed 18 TitleOnCompletion string 19 // SubStatus indicates this progress should be rendered as a sub-item 20 SubStatus bool 21 // RemoveOnCompletion indicates this progress line will be removed when completed 22 RemoveOnCompletion bool 23 // value is the value to display -- not public as SetValue needs to be called to initialize this progress 24 value string 25 } 26 27 func (e *CatalogerTask) init() { 28 e.prog = progress.NewManual(-1) 29 30 bus.Publish(partybus.Event{ 31 Type: event.CatalogerTaskStarted, 32 Source: e, 33 }) 34 } 35 36 func (e *CatalogerTask) SetCompleted() { 37 if e.prog != nil { 38 e.prog.SetCompleted() 39 } 40 } 41 42 func (e *CatalogerTask) SetValue(value string) { 43 if e.prog == nil { 44 e.init() 45 } 46 e.value = value 47 } 48 49 func (e *CatalogerTask) GetValue() string { 50 return e.value 51 } 52 53 func (e *CatalogerTask) GetMonitor() *progress.Manual { 54 return e.prog 55 }