diff --git a/connector/docker.go b/connector/docker.go index db28638..59aeccb 100644 --- a/connector/docker.go +++ b/connector/docker.go @@ -48,7 +48,7 @@ func NewDocker() (Connector, error) { cm := &Docker{ client: client, containers: make(map[string]*container.Container), - noneStack: container.NewStack(""), + noneStack: container.NewStack("", "none"), stacks: make(map[string]*container.Stack), needsRefresh: make(chan string, 60), statuses: make(chan StatusUpdate, 60), @@ -227,7 +227,7 @@ func (cm *Docker) initContainerStack(c *container.Container, labels map[string]s c.Stack = stack } else { // create and remember the new stack - c.Stack = container.NewStack(stackName) + c.Stack = container.NewStack(stackName, "compose") c.Stack.WorkDir = labels["com.docker.compose.project.working_dir"] c.Stack.Config = labels["com.docker.compose.project.config_files"] cm.stacks[stackName] = c.Stack diff --git a/connector/mock.go b/connector/mock.go index 7625f1d..3d97e84 100644 --- a/connector/mock.go +++ b/connector/mock.go @@ -23,7 +23,7 @@ type Mock struct { func NewMock() (Connector, error) { cs := &Mock{ - noneStack: container.NewStack(""), + noneStack: container.NewStack("", "none"), } go cs.Init() go cs.Loop() @@ -33,8 +33,8 @@ func NewMock() (Connector, error) { // Create Mock containers func (cs *Mock) Init() { rand.Seed(int64(time.Now().Nanosecond())) - stack1 := container.NewStack("stack1") - stack2 := container.NewStack("stack2") + stack1 := container.NewStack("stack1", "compose") + stack2 := container.NewStack("stack2", "compose") for i := 0; i < 2; i++ { cs.makeContainer(3, true, cs.noneStack) diff --git a/connector/runc.go b/connector/runc.go index 670c4d1..e43e3d0 100644 --- a/connector/runc.go +++ b/connector/runc.go @@ -75,7 +75,7 @@ func NewRunc() (Connector, error) { opts: opts, factory: factory, containers: make(map[string]*container.Container), - noneStack: container.NewStack(""), + noneStack: container.NewStack("", "none"), libContainers: make(map[string]libcontainer.Container), closed: make(chan struct{}), lock: sync.RWMutex{}, diff --git a/container/main.go b/container/main.go index 2bf47bd..04cf4f7 100644 --- a/container/main.go +++ b/container/main.go @@ -54,11 +54,11 @@ func New(id string, collector collector.Collector, manager manager.Manager) *Con } } -func NewStack(name string) *Stack { +func NewStack(name string, stackType string) *Stack { p := &Stack{Name: name} // create a compact row for the stack widgets := compact.NewCompactRow() - meta := models.NewMeta("name", name) + meta := models.NewMeta("name", name, "stackType", stackType) widgets.SetMeta(meta) p.Widgets = widgets return p diff --git a/cwidgets/compact/status.go b/cwidgets/compact/status.go index 6a5707a..e91b978 100644 --- a/cwidgets/compact/status.go +++ b/cwidgets/compact/status.go @@ -15,6 +15,7 @@ const ( // Status indicator type Status struct { *ui.Block + stack []ui.Cell status []ui.Cell health []ui.Cell } @@ -22,6 +23,7 @@ type Status struct { func NewStatus() CompactCol { s := &Status{ Block: ui.NewBlock(), + stack: []ui.Cell{{Ch: ' '}}, health: []ui.Cell{{Ch: ' '}}, } s.Height = 1 @@ -33,6 +35,10 @@ func NewStatus() CompactCol { func (s *Status) Buffer() ui.Buffer { buf := s.Block.Buffer() x := 0 + for _, c := range s.stack { + buf.Set(s.InnerX()+x, s.InnerY(), c) + x += c.Width() + } for _, c := range s.health { buf.Set(s.InnerX()+x, s.InnerY(), c) x += c.Width() @@ -46,6 +52,7 @@ func (s *Status) Buffer() ui.Buffer { } func (s *Status) SetMeta(m models.Meta) { + s.setStackType(m.Get("stackType")) s.setState(m.Get("state")) s.setHealth(m.Get("health")) } @@ -56,7 +63,7 @@ func (s *Status) SetMetrics(models.Metrics) {} func (s *Status) Highlight() {} func (s *Status) UnHighlight() {} func (s *Status) Header() string { return "" } -func (s *Status) FixedWidth() int { return 3 } +func (s *Status) FixedWidth() int { return 4 } func (s *Status) setState(val string) { // defaults @@ -65,7 +72,7 @@ func (s *Status) setState(val string) { switch val { case "": - text = "▼" + text = " " case "running": color = ui.ThemeAttr("status.ok") case "exited": @@ -96,3 +103,15 @@ func (s *Status) setHealth(val string) { s.health = ui.TextCells(mark, color, ui.ColorDefault) } + +func (s *Status) setStackType(stackType string) { + var text string + // stackType may be compose or none + if stackType != "" { + text = "▾" + } else { + text = " " + } + color := ui.ColorDefault + s.stack = ui.TextCells(text, color, ui.ColorDefault) +}