37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package cpu
|
|
|
|
import (
|
|
"finally-a-monolithic-linux-hw-monitor/app/cpu/proc"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func RenderCPU(console *strings.Builder, proc *proc.Proc) {
|
|
// Move cursor to top-left (0,0) without clearing full buffer (flicker-free)
|
|
fmt.Fprint(console, "\033[H")
|
|
fmt.Fprintf(console, "=== %s ===\n", proc.Model())
|
|
|
|
RenderTemperatureSensors(console, proc)
|
|
RenderPowerSensors(console, proc)
|
|
}
|
|
|
|
func RenderTemperatureSensors(console *strings.Builder, proc *proc.Proc) {
|
|
temps, _ := proc.SensorReader.ReadTemperatureSensors()
|
|
fmt.Fprint(console, "--- Temperature ---\n")
|
|
for _, sensor := range temps {
|
|
tempC := sensor.TempC
|
|
tempF := (tempC * 9 / 5) + 32
|
|
// \033[K clears from cursor to end of line (prevents lingering chars)
|
|
fmt.Fprintf(console, "Sensor: %-25s | %5.1f°C (%5.1f°F)\033[K\n", sensor.Name, tempC, tempF)
|
|
}
|
|
}
|
|
|
|
func RenderPowerSensors(console *strings.Builder, proc *proc.Proc) {
|
|
fmt.Fprint(console, "--- Power ---\n")
|
|
power, _ := proc.SensorReader.ReadPowerSensors()
|
|
for _, sensor := range power {
|
|
// \033[K clears from cursor to end of line (prevents lingering chars)
|
|
fmt.Fprintf(console, "Sensor: %-25s | %5.1fW\033[K\n", sensor.Name, sensor.Watts)
|
|
}
|
|
}
|