initial refactor of all column widgets to standard interface

This commit is contained in:
Bradley Cicenas
2019-06-08 21:34:43 +00:00
parent 1271ce96e8
commit 923edb967e
9 changed files with 198 additions and 178 deletions

View File

@@ -1,9 +1,56 @@
package compact
import (
"fmt"
"github.com/bcicen/ctop/cwidgets"
"github.com/bcicen/ctop/models"
ui "github.com/gizak/termui"
)
type NameCol struct {
*TextCol
}
func (w *NameCol) SetMeta(m models.Meta) {
if s, ok := m["name"]; ok {
w.Text = s
}
}
func (w *NameCol) SetMetrics(m models.Metrics) {
}
type CIDCol struct {
*TextCol
}
type NetCol struct {
*TextCol
}
func (w *NetCol) SetMetrics(m models.Metrics) {
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat(m.NetRx), cwidgets.ByteFormat(m.NetTx))
w.Text = label
}
type IOCol struct {
*TextCol
}
func (w *IOCol) SetMetrics(m models.Metrics) {
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat(m.IOBytesRead), cwidgets.ByteFormat(m.IOBytesWrite))
w.Text = label
}
type PIDCol struct {
*TextCol
}
func (w *PIDCol) SetMetrics(m models.Metrics) {
w.Text = fmt.Sprintf("%d", m.Pids)
}
type TextCol struct {
*ui.Par
}
@@ -28,10 +75,7 @@ func (w *TextCol) UnHighlight() {
w.TextBgColor = ui.ThemeAttr("par.text.bg")
}
func (w *TextCol) Reset() {
w.Text = "-"
}
func (w *TextCol) Set(s string) {
w.Text = s
}
//func (w *TextCol) Set(s string) { w.Text = s }
func (w *TextCol) Reset() { w.Text = "-" }
func (w *TextCol) SetMeta(models.Meta) {}
func (w *TextCol) SetMetrics(models.Metrics) {}