mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add mem% as sortable field
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user