refactor cpu gauge into standalone widget

This commit is contained in:
Bradley Cicenas
2017-01-06 02:01:57 +00:00
parent 11376c24e4
commit 3ec384414d
5 changed files with 56 additions and 26 deletions

26
widgets/cpu.go Normal file
View File

@@ -0,0 +1,26 @@
package widgets
import (
"fmt"
"strconv"
ui "github.com/gizak/termui"
)
type CPU struct {
*ui.Gauge
}
func NewCPU() *CPU {
return &CPU{mkGauge()}
}
func (c *CPU) Set(val int) {
c.BarColor = colorScale(val)
c.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
if val < 5 {
val = 5
c.BarColor = ui.ColorBlack
}
c.Percent = val
}