ctop/cwidgets/expanded/info.go

36 lines
639 B
Go
Raw Normal View History

2017-03-06 08:51:50 +00:00
package expanded
import (
ui "github.com/gizak/termui"
)
var displayInfo = []string{"id", "name", "image", "ports", "state"}
2017-03-06 08:51:50 +00:00
type Info struct {
*ui.Table
data map[string]string
}
func NewInfo(id string) *Info {
p := ui.NewTable()
p.Height = 4
p.Width = colWidth[0]
2017-03-07 23:40:03 +00:00
p.FgColor = ui.ThemeAttr("par.text.fg")
2017-03-10 00:16:40 +00:00
p.Separator = false
2017-03-06 08:51:50 +00:00
i := &Info{p, make(map[string]string)}
i.Set("id", id)
2017-03-06 08:51:50 +00:00
return i
}
func (w *Info) Set(k, v string) {
w.data[k] = v
// rebuild rows
w.Rows = [][]string{}
for _, k := range displayInfo {
if v, ok := w.data[k]; ok {
w.Rows = append(w.Rows, []string{k, v})
}
2017-03-06 08:51:50 +00:00
}
w.Height = len(w.Rows) + 2
2017-03-06 08:51:50 +00:00
}