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,21 +1,49 @@
|
||||
package compact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/bcicen/ctop/cwidgets"
|
||||
"github.com/bcicen/ctop/models"
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type CPUCol struct {
|
||||
*GaugeCol
|
||||
}
|
||||
|
||||
func (w *CPUCol) SetMetrics(m models.Metrics) {
|
||||
val := m.CPUUtil
|
||||
w.BarColor = colorScale(val)
|
||||
w.Label = fmt.Sprintf("%d%%", val)
|
||||
|
||||
if val > 100 {
|
||||
val = 100
|
||||
}
|
||||
w.Percent = val
|
||||
}
|
||||
|
||||
type MemCol struct {
|
||||
*GaugeCol
|
||||
}
|
||||
|
||||
func (w *MemCol) SetMetrics(m models.Metrics) {
|
||||
w.BarColor = ui.ThemeAttr("gauge.bar.bg")
|
||||
w.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(m.MemUsage), cwidgets.ByteFormat(m.MemLimit))
|
||||
w.Percent = m.MemPercent
|
||||
}
|
||||
|
||||
type GaugeCol struct {
|
||||
*ui.Gauge
|
||||
}
|
||||
|
||||
func NewGaugeCol() *GaugeCol {
|
||||
g := ui.NewGauge()
|
||||
g := &GaugeCol{ui.NewGauge()}
|
||||
g.Height = 1
|
||||
g.Border = false
|
||||
g.Percent = 0
|
||||
g.PaddingBottom = 0
|
||||
g.Label = "-"
|
||||
return &GaugeCol{g}
|
||||
g.Reset()
|
||||
return g
|
||||
}
|
||||
|
||||
func (w *GaugeCol) Reset() {
|
||||
@@ -23,11 +51,30 @@ func (w *GaugeCol) Reset() {
|
||||
w.Percent = 0
|
||||
}
|
||||
|
||||
func (w *GaugeCol) Buffer() ui.Buffer {
|
||||
// if bar would not otherwise be visible, set a minimum
|
||||
// percentage value and low-contrast color for structure
|
||||
if w.Percent < 5 {
|
||||
w.Percent = 5
|
||||
w.BarColor = ui.ColorBlack
|
||||
}
|
||||
|
||||
return w.Gauge.Buffer()
|
||||
}
|
||||
|
||||
// GaugeCol implements CompactCol
|
||||
func (w *GaugeCol) SetMeta(models.Meta) {}
|
||||
|
||||
// GaugeCol implements CompactCol
|
||||
func (w *GaugeCol) SetMetrics(models.Metrics) {}
|
||||
|
||||
// GaugeCol implements CompactCol
|
||||
func (w *GaugeCol) Highlight() {
|
||||
w.Bg = ui.ThemeAttr("par.text.fg")
|
||||
w.PercentColor = ui.ThemeAttr("par.text.hi")
|
||||
}
|
||||
|
||||
// GaugeCol implements CompactCol
|
||||
func (w *GaugeCol) UnHighlight() {
|
||||
w.Bg = ui.ThemeAttr("par.text.bg")
|
||||
w.PercentColor = ui.ThemeAttr("par.text.bg")
|
||||
|
||||
Reference in New Issue
Block a user