mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
initial refactor of all column widgets to standard interface
This commit is contained in:
@@ -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) {}
|
||||
|
||||
Reference in New Issue
Block a user