2017-03-03 07:57:26 +00:00
|
|
|
package compact
|
|
|
|
|
|
|
|
import (
|
2019-06-08 21:34:43 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/bcicen/ctop/cwidgets"
|
|
|
|
"github.com/bcicen/ctop/models"
|
2020-01-02 14:00:55 +00:00
|
|
|
|
2017-03-03 07:57:26 +00:00
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
2019-06-08 21:34:43 +00:00
|
|
|
type NameCol struct {
|
|
|
|
*TextCol
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:05:21 +00:00
|
|
|
func NewNameCol() CompactCol {
|
2020-11-27 21:12:16 +00:00
|
|
|
c := &NameCol{NewTextCol("NAME")}
|
|
|
|
c.fWidth = 30
|
|
|
|
return c
|
2019-06-08 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 23:05:21 +00:00
|
|
|
func (w *NameCol) SetMeta(m models.Meta) {
|
2020-10-31 14:52:30 +00:00
|
|
|
w.setText(m.Get("name"))
|
2019-06-08 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type CIDCol struct {
|
|
|
|
*TextCol
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:05:21 +00:00
|
|
|
func NewCIDCol() CompactCol {
|
2020-10-31 14:52:30 +00:00
|
|
|
c := &CIDCol{NewTextCol("CID")}
|
|
|
|
c.fWidth = 12
|
|
|
|
return c
|
2019-07-05 23:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *CIDCol) SetMeta(m models.Meta) {
|
2020-10-31 14:52:30 +00:00
|
|
|
w.setText(m.Get("id"))
|
2019-07-05 23:05:21 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 21:34:43 +00:00
|
|
|
type NetCol struct {
|
|
|
|
*TextCol
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:05:21 +00:00
|
|
|
func NewNetCol() CompactCol {
|
|
|
|
return &NetCol{NewTextCol("NET RX/TX")}
|
|
|
|
}
|
|
|
|
|
2019-06-08 21:34:43 +00:00
|
|
|
func (w *NetCol) SetMetrics(m models.Metrics) {
|
2020-10-25 16:02:31 +00:00
|
|
|
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat64Short(m.NetRx), cwidgets.ByteFormat64Short(m.NetTx))
|
2020-10-31 14:52:30 +00:00
|
|
|
w.setText(label)
|
2019-06-08 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type IOCol struct {
|
|
|
|
*TextCol
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:05:21 +00:00
|
|
|
func NewIOCol() CompactCol {
|
|
|
|
return &IOCol{NewTextCol("IO R/W")}
|
|
|
|
}
|
|
|
|
|
2019-06-08 21:34:43 +00:00
|
|
|
func (w *IOCol) SetMetrics(m models.Metrics) {
|
2020-10-25 16:02:31 +00:00
|
|
|
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat64Short(m.IOBytesRead), cwidgets.ByteFormat64Short(m.IOBytesWrite))
|
2020-10-31 14:52:30 +00:00
|
|
|
w.setText(label)
|
2019-06-08 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type PIDCol struct {
|
|
|
|
*TextCol
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:05:21 +00:00
|
|
|
func NewPIDCol() CompactCol {
|
|
|
|
w := &PIDCol{NewTextCol("PIDS")}
|
|
|
|
w.fWidth = 4
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
2019-06-08 21:34:43 +00:00
|
|
|
func (w *PIDCol) SetMetrics(m models.Metrics) {
|
2020-10-31 14:52:30 +00:00
|
|
|
w.setText(fmt.Sprintf("%d", m.Pids))
|
2019-06-08 21:34:43 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 07:57:26 +00:00
|
|
|
type TextCol struct {
|
|
|
|
*ui.Par
|
2019-07-05 23:05:21 +00:00
|
|
|
header string
|
|
|
|
fWidth int
|
2017-03-03 07:57:26 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 23:05:21 +00:00
|
|
|
func NewTextCol(header string) *TextCol {
|
|
|
|
p := ui.NewPar("-")
|
2017-03-03 07:57:26 +00:00
|
|
|
p.Border = false
|
|
|
|
p.Height = 1
|
|
|
|
p.Width = 20
|
2020-10-31 14:52:30 +00:00
|
|
|
|
|
|
|
return &TextCol{
|
|
|
|
Par: p,
|
|
|
|
header: header,
|
|
|
|
fWidth: 0,
|
|
|
|
}
|
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")
|
|
|
|
}
|
|
|
|
|
2020-10-31 14:52:30 +00:00
|
|
|
// TextCol implements CompactCol
|
|
|
|
func (w *TextCol) Reset() { w.setText("-") }
|
2019-06-08 21:34:43 +00:00
|
|
|
func (w *TextCol) SetMeta(models.Meta) {}
|
|
|
|
func (w *TextCol) SetMetrics(models.Metrics) {}
|
2019-07-05 23:05:21 +00:00
|
|
|
func (w *TextCol) Header() string { return w.header }
|
|
|
|
func (w *TextCol) FixedWidth() int { return w.fWidth }
|
2020-10-31 14:52:30 +00:00
|
|
|
|
|
|
|
func (w *TextCol) setText(s string) {
|
|
|
|
if w.fWidth > 0 && len(s) > w.fWidth {
|
|
|
|
s = s[0:w.fWidth]
|
|
|
|
}
|
|
|
|
w.Text = s
|
|
|
|
}
|