mirror of
https://github.com/bcicen/ctop.git
synced 2025-11-15 07:25:49 +01:00
restructure compact widgets
This commit is contained in:
35
cwidgets/compact/setters.go
Normal file
35
cwidgets/compact/setters.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package compact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/bcicen/ctop/cwidgets"
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
func (row *Compact) SetNet(rx int64, tx int64) {
|
||||
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat(rx), cwidgets.ByteFormat(tx))
|
||||
row.Net.Set(label)
|
||||
}
|
||||
|
||||
func (row *Compact) SetCPU(val int) {
|
||||
row.Cpu.BarColor = colorScale(val)
|
||||
row.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
|
||||
if val < 5 {
|
||||
val = 5
|
||||
row.Cpu.BarColor = ui.ColorBlack
|
||||
}
|
||||
row.Cpu.Percent = val
|
||||
}
|
||||
|
||||
func (row *Compact) SetMem(val int64, limit int64, percent int) {
|
||||
row.Memory.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(val), cwidgets.ByteFormat(limit))
|
||||
if percent < 5 {
|
||||
percent = 5
|
||||
row.Memory.BarColor = ui.ColorBlack
|
||||
} else {
|
||||
row.Memory.BarColor = ui.ColorGreen
|
||||
}
|
||||
row.Memory.Percent = percent
|
||||
}
|
||||
Reference in New Issue
Block a user