add mem% as sortable field

This commit is contained in:
Bradley Cicenas
2017-01-06 12:02:56 +00:00
parent d5e4782839
commit 6d63d09c83
5 changed files with 31 additions and 24 deletions

View File

@@ -35,23 +35,21 @@ func (w *Compact) Row() *ui.Row {
)
}
func (w *Compact) SetCPU(val float64) {
intVal := round(val)
w.Cpu.BarColor = colorScale(intVal)
w.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(intVal))
if intVal < 5 {
intVal = 5
func (w *Compact) SetCPU(val int) {
w.Cpu.BarColor = colorScale(val)
w.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
if val < 5 {
val = 5
w.Cpu.BarColor = ui.ColorBlack
}
w.Cpu.Percent = intVal
w.Cpu.Percent = val
}
func (w *Compact) SetNet(rx int64, tx int64) {
w.Net.Text = fmt.Sprintf("%s / %s", byteFormat(rx), byteFormat(tx))
}
func (w *Compact) SetMem(val int64, limit int64) {
percent := round((float64(val) / float64(limit)) * 100)
func (w *Compact) SetMem(val int64, limit int64, percent int) {
w.Memory.Label = fmt.Sprintf("%s / %s", byteFormat(val), byteFormat(limit))
if percent < 5 {
percent = 5

View File

@@ -2,7 +2,6 @@ package widgets
import (
"fmt"
"math"
"strconv"
ui "github.com/gizak/termui"
@@ -30,10 +29,6 @@ func byteFormat(n int64) string {
return fmt.Sprintf("%sG", strconv.FormatInt(n, 10))
}
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}
func compactPar(s string) *ui.Par {
p := ui.NewPar(s)
p.Border = false