initial proof of concept
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"finally-a-monolithic-linux-hw-monitor/app/cpu"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Run() {
|
||||
// Clear terminal screen and hide cursor
|
||||
fmt.Print("\033[2J\033[?25l")
|
||||
|
||||
// Ensure cursor is restored when exiting (Ctrl+C / SIGTERM)
|
||||
cleanupChannel := make(chan os.Signal, 1)
|
||||
signal.Notify(cleanupChannel, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-cleanupChannel
|
||||
// Restore cursor and move below output
|
||||
fmt.Print("\033[?25h\n")
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
console := &strings.Builder{}
|
||||
cpu.RenderCPU(console)
|
||||
|
||||
console.WriteString("\nPress Ctrl+C to exit.\033[K\n")
|
||||
fmt.Print(console.String())
|
||||
|
||||
<-ticker.C
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user