mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
refactor cpu gauge into standalone widget
This commit is contained in:
16
widgets.go
16
widgets.go
@@ -2,8 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/bcicen/ctop/widgets"
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ type Widgets struct {
|
||||
cid *ui.Par
|
||||
net *ui.Par
|
||||
name *ui.Par
|
||||
cpu *ui.Gauge
|
||||
cpu *widgets.CPU
|
||||
memory *ui.Gauge
|
||||
}
|
||||
|
||||
@@ -25,16 +25,6 @@ func (w *Widgets) MakeRow() *ui.Row {
|
||||
)
|
||||
}
|
||||
|
||||
func (w *Widgets) 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 = val
|
||||
}
|
||||
|
||||
func (w *Widgets) SetNet(rx int64, tx int64) {
|
||||
w.net.Text = fmt.Sprintf("%s / %s", byteFormat(rx), byteFormat(tx))
|
||||
}
|
||||
@@ -71,7 +61,7 @@ func NewWidgets(id string, names string) *Widgets {
|
||||
net.Width = 20
|
||||
net.TextFgColor = ui.ColorWhite
|
||||
|
||||
return &Widgets{cid, net, name, mkGauge(), mkGauge()}
|
||||
return &Widgets{cid, net, name, widgets.NewCPU(), mkGauge()}
|
||||
}
|
||||
|
||||
func mkGauge() *ui.Gauge {
|
||||
|
||||
Reference in New Issue
Block a user