Files
finally-a-monolithic-linux-…/app/cpu/cpu.go
T
2026-08-04 20:12:47 +00:00

31 lines
810 B
Go

package cpu
import (
"finally-a-monolithic-linux-hw-monitor/app/cpu/proc"
"fmt"
"strings"
)
func RenderCPU(console *strings.Builder) {
proc, err := proc.GetProc()
if err != nil {
return
}
// Move cursor to top-left (0,0) without clearing full buffer (flicker-free)
console.WriteString("\033[H")
console.WriteString(fmt.Sprintf("=== %s ===\n", proc.Model()))
RenderTemperatures(console, proc)
}
func RenderTemperatures(console *strings.Builder, proc proc.Proc) {
temps, _ := proc.SensorReader.ReadTemperatureSensors()
for _, sensor := range temps {
tempC := sensor.TempC
tempF := (tempC * 9 / 5) + 32
// \033[K clears from cursor to end of line (prevents lingering chars)
console.WriteString(fmt.Sprintf("Sensor: %-25s | %5.1f°C (%5.1f°F)\033[K\n", sensor.Name, tempC, tempF))
}
}