mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
#191 Show mark for stack
This commit is contained in:
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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{},
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user