summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2021-01-26 14:16:33 -0600
committerSean E. Russell <ser@ser1.net>2021-01-26 14:16:33 -0600
commita216c41390e543cb37f29230175de59c15bcfb62 (patch)
treee5b23d4bc20536b28dbcb5d206d76f9f924ad58d
parent67831ac97c8a4c45ee08d438214da41372be10df (diff)
Fixes #7, sort temps starting with 'core' at topv4.2
-rw-r--r--widgets/temp.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/widgets/temp.go b/widgets/temp.go
index f5632df..05328f7 100644
--- a/widgets/temp.go
+++ b/widgets/temp.go
@@ -4,6 +4,7 @@ import (
"fmt"
"image"
"sort"
+ "strings"
"time"
"github.com/VictoriaMetrics/metrics"
@@ -29,6 +30,7 @@ type TempWidget struct {
TempHighColor ui.Color
TempScale TempScale
temps map[string]float64
+ keys ordered
}
func NewTempWidget(tempScale TempScale, filter []string) *TempWidget {
@@ -81,13 +83,17 @@ func (temp *TempWidget) EnableMetric() {
func (temp *TempWidget) Draw(buf *ui.Buffer) {
temp.Block.Draw(buf)
- var keys []string
- for key := range temp.Data {
- keys = append(keys, key)
+ if len(temp.keys) != len(temp.Data) {
+ temp.keys = make(ordered, len(temp.Data))
+ i := 0
+ for key := range temp.Data {
+ temp.keys[i] = key
+ i++
+ }
+ sort.Sort(temp.keys)
}
- sort.Strings(keys)
- for y, key := range keys {
+ for y, key := range temp.keys {
if y+1 > temp.Inner.Dy() {
break
}
@@ -125,3 +131,18 @@ func (temp *TempWidget) update() {
}
}
}
+
+type ordered []string
+
+func (o ordered) Len() int { return len(o) }
+func (o ordered) Swap(i, j int) { o[j], o[i] = o[i], o[j] }
+func (o ordered) Less(i, j int) bool {
+ if strings.HasPrefix(o[i], "core") {
+ if !strings.HasPrefix(o[j], "core") {
+ return true
+ }
+ } else if strings.HasPrefix(o[j], "core") {
+ return false
+ }
+ return o[i] < o[j]
+}