abstract terminal interface

This commit is contained in:
alu
2026-08-07 14:49:21 -07:00
parent 691dba7687
commit 5c4d16857b
10 changed files with 91 additions and 40 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
package drivers
import (
"finally-a-monolithic-linux-hw-monitor/app/common"
"fmt"
"os"
"path/filepath"
@@ -28,18 +29,18 @@ func NewRaplDriver() (*RaplDriver, error) {
return &r, err
}
func (r *RaplDriver) Render(console *strings.Builder) error {
fmt.Fprint(console, "--- Power ---\033[K\n")
func (r *RaplDriver) Render(term common.Terminal) error {
p, err := r.Read()
if err != nil {
return err
}
power := p.([]PowerSensor)
term.Subheader("Power")
for _, sensor := range power {
// \033[K clears from cursor to end of line (prevents lingering chars)
fmt.Fprintf(console, "%-16s | %.2f W\033[K\n", sensor.Name, sensor.Watts)
term.Print(fmt.Sprintf("%-16s | %.2f W", sensor.Name, sensor.Watts))
}
return nil