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
This commit is contained in:
Alexandr Kozlenkov 2017-08-23 22:38:14 +03:00 committed by Bradley Cicenas
parent eaa7ad85f8
commit 626d50d3e9
4 changed files with 41 additions and 4 deletions

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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