fix issue with intel cpu temperature label order
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -51,10 +52,7 @@ func (r *HwmonDriver) Render(term common.Terminal) error {
|
|||||||
term.Subheader("Temperature")
|
term.Subheader("Temperature")
|
||||||
|
|
||||||
for _, sensor := range temps {
|
for _, sensor := range temps {
|
||||||
tempC := sensor.TempC
|
term.Print(fmt.Sprintf("%-16s | %.2f °C", sensor.Name, sensor.TempC))
|
||||||
tempF := (tempC * 9 / 5) + 32
|
|
||||||
// \033[K clears from cursor to end of line (prevents lingering chars)
|
|
||||||
term.Print(fmt.Sprintf("%-16s | %.2f °C (%.3f °F)", sensor.Name, tempC, tempF))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -66,6 +64,11 @@ func (r *HwmonDriver) Read() (any, error) {
|
|||||||
return nil, fmt.Errorf("no temperature inputs found in %s", r.hwmonDir)
|
return nil, fmt.Errorf("no temperature inputs found in %s", r.hwmonDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort input paths by numerical index (temp1_input, temp2_input, ... temp10_input)
|
||||||
|
sort.Slice(inputs, func(i, j int) bool {
|
||||||
|
return extractSensorIndex(inputs[i]) < extractSensorIndex(inputs[j])
|
||||||
|
})
|
||||||
|
|
||||||
temps := make([]TemperatureSensor, 0, len(inputs))
|
temps := make([]TemperatureSensor, 0, len(inputs))
|
||||||
|
|
||||||
for _, inputPath := range inputs {
|
for _, inputPath := range inputs {
|
||||||
@@ -96,3 +99,15 @@ func (r *HwmonDriver) Read() (any, error) {
|
|||||||
|
|
||||||
return temps, nil
|
return temps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper to extract the integer index from "temp<N>_input"
|
||||||
|
func extractSensorIndex(path string) int {
|
||||||
|
base := filepath.Base(path)
|
||||||
|
trimmed := strings.TrimPrefix(base, "temp")
|
||||||
|
trimmed = strings.TrimSuffix(trimmed, "_input")
|
||||||
|
idx, err := strconv.Atoi(trimmed)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return idx
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user