ctop/cwidgets/compact/setters.go

49 lines
1.1 KiB
Go
Raw Normal View History

2017-03-06 00:15:32 +00:00
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)
}
2017-03-12 01:35:40 +00:00
func (row *Compact) SetIO(read int64, write int64) {
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat(read), cwidgets.ByteFormat(write))
row.IO.Set(label)
}
func (row *Compact) SetPids(val int) {
label := fmt.Sprintf("%s", strconv.Itoa(val))
row.Pids.Set(label)
}
2017-03-06 00:15:32 +00:00
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
2017-03-07 23:40:03 +00:00
row.Cpu.BarColor = ui.ThemeAttr("gauge.bar.bg")
2017-03-06 00:15:32 +00:00
}
2017-03-12 22:00:17 +00:00
if val > 100 {
val = 100
}
2017-03-06 00:15:32 +00:00
row.Cpu.Percent = val
}
func (row *Compact) SetMem(val int64, limit int64, percent int) {
2017-08-09 12:05:45 +00:00
row.Mem.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(val), cwidgets.ByteFormat(limit))
2017-03-06 00:15:32 +00:00
if percent < 5 {
percent = 5
2017-08-09 12:05:45 +00:00
row.Mem.BarColor = ui.ColorBlack
2017-03-06 00:15:32 +00:00
} else {
2017-08-09 12:05:45 +00:00
row.Mem.BarColor = ui.ThemeAttr("gauge.bar.bg")
2017-03-06 00:15:32 +00:00
}
2017-08-09 12:05:45 +00:00
row.Mem.Percent = percent
2017-03-06 00:15:32 +00:00
}