Files
ctop/cwidgets/compact/text.go
T

82 lines
1.5 KiB
Go
Raw Normal View History

2017-03-03 07:57:26 +00:00
package compact
import (
"fmt"
"github.com/bcicen/ctop/cwidgets"
"github.com/bcicen/ctop/models"
2017-03-03 07:57:26 +00:00
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)
}
2017-03-03 07:57:26 +00:00
type TextCol struct {
*ui.Par
}
func NewTextCol(s string) *TextCol {
p := ui.NewPar(s)
p.Border = false
p.Height = 1
p.Width = 20
2017-08-28 01:48:13 +00:00
return &TextCol{p}
2017-03-03 07:57:26 +00:00
}
2017-03-03 08:02:08 +00:00
func (w *TextCol) Highlight() {
2018-09-17 01:24:06 +00:00
w.Bg = ui.ThemeAttr("par.text.fg")
2017-08-28 01:48:13 +00:00
w.TextFgColor = ui.ThemeAttr("par.text.hi")
2017-03-03 08:02:08 +00:00
w.TextBgColor = ui.ThemeAttr("par.text.fg")
}
func (w *TextCol) UnHighlight() {
2018-09-17 01:24:06 +00:00
w.Bg = ui.ThemeAttr("par.text.bg")
2017-08-28 01:48:13 +00:00
w.TextFgColor = ui.ThemeAttr("par.text.fg")
2017-03-03 08:02:08 +00:00
w.TextBgColor = ui.ThemeAttr("par.text.bg")
}
//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) {}