diff --git a/container.go b/container.go index 43a578b..9f50cda 100644 --- a/container.go +++ b/container.go @@ -8,6 +8,7 @@ import ( type Container struct { id string name string + state string metrics collector.Metrics collect collector.Collector widgets widgets.ContainerWidgets @@ -21,6 +22,15 @@ func (c *Container) Collapse() { c.widgets = widgets.NewCompact(c.id, c.name) } +func (c *Container) SetState(s string) { + c.state = s + c.widgets.SetStatus(s) + // start collector if necessary + if s == "running" && !c.collect.Running() { + c.Collect() + } +} + func (c *Container) Collect() { c.collect.Start() go func() { diff --git a/containermap.go b/containermap.go index 8a68c1d..a291e5d 100644 --- a/containermap.go +++ b/containermap.go @@ -62,11 +62,7 @@ func (cm *ContainerMap) Refresh() { removeIDs = append(removeIDs, id) continue } - // start collector if necessary - if states[id] == "running" && !c.collect.Running() { - c.Collect() - } - c.widgets.SetStatus(states[id]) + c.SetState(states[id]) } // remove dead containers