refactor dockersource container refresh into channel

This commit is contained in:
Bradley Cicenas
2017-03-05 06:46:41 +00:00
parent 8fb5c5de59
commit 3172f141f9
9 changed files with 85 additions and 100 deletions

View File

@@ -23,3 +23,13 @@ func (w *GaugeCol) Reset() {
w.Label = "-"
w.Percent = 0
}
func colorScale(n int) ui.Attribute {
if n > 70 {
return ui.ColorRed
}
if n > 30 {
return ui.ColorYellow
}
return ui.ColorGreen
}

View File

@@ -24,8 +24,9 @@ func (cg *CompactGrid) Align() {
// Update y recursively
cg.header.SetY(cg.Y)
y := cg.Y + 1
for n, r := range cg.Rows {
r.SetY(y + n)
for _, r := range cg.Rows {
r.SetY(y)
y += r.Height
}
// Update width recursively
cg.header.SetWidth(cg.Width)

View File

@@ -28,10 +28,14 @@ type Compact struct {
Height int
}
func NewCompact(id, name string) *Compact {
func NewCompact(id string) *Compact {
// truncate container id
if len(id) > 12 {
id = id[:12]
}
row := &Compact{
Status: NewStatus(),
Name: NewTextCol(name),
Name: NewTextCol("-"),
Cid: NewTextCol(id),
Cpu: NewGaugeCol(),
Memory: NewGaugeCol(),
@@ -41,6 +45,14 @@ func NewCompact(id, name string) *Compact {
return row
}
//func (row *Compact) ToggleExpand() {
//if row.Height == 1 {
//row.Height = 4
//} else {
//row.Height = 1
//}
//}
func (row *Compact) SetMetrics(m metrics.Metrics) {
row.SetCPU(m.CPUUtil)
row.SetNet(m.NetRx, m.NetTx)
@@ -114,7 +126,7 @@ func (row *Compact) SetNet(rx int64, tx int64) {
}
func (row *Compact) SetCPU(val int) {
row.Cpu.BarColor = cwidgets.ColorScale(val)
row.Cpu.BarColor = colorScale(val)
row.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
if val < 5 {
val = 5

View File

@@ -3,8 +3,6 @@ package cwidgets
import (
"fmt"
"strconv"
ui "github.com/gizak/termui"
)
const (
@@ -48,13 +46,3 @@ func getPrecision(f float64) int {
}
return 2 // default precision
}
func ColorScale(n int) ui.Attribute {
if n > 70 {
return ui.ColorRed
}
if n > 30 {
return ui.ColorYellow
}
return ui.ColorGreen
}