diff --git a/connector/docker.go b/connector/docker.go index db5a2cf..21f3552 100644 --- a/connector/docker.go +++ b/connector/docker.go @@ -85,6 +85,7 @@ func (cm *Docker) refresh(c *container.Container) { c.SetMeta("image", insp.Config.Image) c.SetMeta("ports", portsFormat(insp.NetworkSettings.Ports)) c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006")) + c.SetMeta("health", insp.State.Health.Status) c.SetState(insp.State.Status) } @@ -110,6 +111,7 @@ func (cm *Docker) refreshAll() { c := cm.MustGet(i.ID) c.SetMeta("name", shortName(i.Names[0])) c.SetState(i.State) + cm.HealthCheck(i.ID) cm.needsRefresh <- c.Id } } @@ -158,7 +160,11 @@ func (cm *Docker) All() (containers container.Containers) { cm.lock.Lock() for _, c := range cm.containers { containers = append(containers, c) + cm.lock.Unlock() + cm.HealthCheck(c.Id) + cm.lock.Lock() } + containers.Sort() containers.Filter() cm.lock.Unlock() @@ -169,3 +175,9 @@ func (cm *Docker) All() (containers container.Containers) { func shortName(name string) string { return strings.Replace(name, "/", "", 1) } + +func (cm *Docker) HealthCheck(id string){ + insp := cm.inspect(id) + c := cm.MustGet(id) + c.SetMeta("health", insp.State.Health.Status) +} diff --git a/cwidgets/compact/main.go b/cwidgets/compact/main.go index 27b35d1..3ceed0e 100644 --- a/cwidgets/compact/main.go +++ b/cwidgets/compact/main.go @@ -56,6 +56,8 @@ func (row *Compact) SetMeta(k, v string) { row.Name.Set(v) case "state": row.Status.Set(v) + case "health": + row.Name.Color(v) } } diff --git a/cwidgets/compact/text.go b/cwidgets/compact/text.go index b8bc8cf..323a554 100644 --- a/cwidgets/compact/text.go +++ b/cwidgets/compact/text.go @@ -6,6 +6,7 @@ import ( type TextCol struct { *ui.Par + isHighlight bool } func NewTextCol(s string) *TextCol { @@ -13,17 +14,23 @@ func NewTextCol(s string) *TextCol { p.Border = false p.Height = 1 p.Width = 20 - return &TextCol{p} + return &TextCol{p, false} } func (w *TextCol) Highlight() { - w.TextFgColor = ui.ThemeAttr("par.text.hi") + if w.TextFgColor ==ui.ThemeAttr("par.text.fg"){ + w.TextFgColor = ui.ThemeAttr("par.text.hi") + } w.TextBgColor = ui.ThemeAttr("par.text.fg") + w.isHighlight = true } func (w *TextCol) UnHighlight() { - w.TextFgColor = ui.ThemeAttr("par.text.fg") + if w.TextFgColor == ui.ThemeAttr("par.text.hi"){ + w.TextFgColor = ui.ThemeAttr("par.text.fg") + } w.TextBgColor = ui.ThemeAttr("par.text.bg") + w.isHighlight = false } func (w *TextCol) Reset() { @@ -33,3 +40,19 @@ func (w *TextCol) Reset() { func (w *TextCol) Set(s string) { w.Text = s } + +func (w *TextCol) Color(s string){ + color := ui.ThemeAttr("par.text.fg") + if w.isHighlight{ + color = ui.ThemeAttr("par.text.hi") + } + switch s { + case "healthy": + color = ui.ColorGreen + case "unhealthy": + color = ui.ColorMagenta + case "starting": + color = ui.ColorYellow + } + w.TextFgColor = color +} diff --git a/cwidgets/single/info.go b/cwidgets/single/info.go index 9f3bfea..aecd47c 100644 --- a/cwidgets/single/info.go +++ b/cwidgets/single/info.go @@ -6,7 +6,7 @@ import ( ui "github.com/gizak/termui" ) -var displayInfo = []string{"id", "name", "image", "ports", "state", "created"} +var displayInfo = []string{"id", "name", "image", "ports", "state", "created", "health"} type Info struct { *ui.Table