From 626d50d3e96cab5f5ab2f3d40d18c0c252f5fb14 Mon Sep 17 00:00:00 2001 From: Alexandr Kozlenkov Date: Wed, 23 Aug 2017 22:38:14 +0300 Subject: [PATCH] Added health row to Info Single mode. Change color status logic. Highlight health status for Name column: - starting - yellow - healthy - green - unhealthy - magenta reformat Fixed misprint Removed unused colors of state widget. Moved changes to another branch Removed unused colors of state widget. Remove swarm changes from master Remove swarm changes from master Remove swarm changes from master --- connector/docker.go | 12 ++++++++++++ cwidgets/compact/main.go | 2 ++ cwidgets/compact/text.go | 29 ++++++++++++++++++++++++++--- cwidgets/single/info.go | 2 +- 4 files changed, 41 insertions(+), 4 deletions(-) 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