statusscreen/main.go

74 lines
1.2 KiB
Go

package main
import (
"fmt"
"github.com/BurntSushi/toml"
tm "github.com/buger/goterm"
"io/ioutil"
"os"
"time"
)
func main() {
config := getConfig("status.toml")
sl := SL{Config: &config}
clock := Clock{Config: &config}
weather := Weather{Config: &config}
pollen := Pollen{Config: &config}
tm.Clear()
tm.Print("\033[?25l")
for {
tm.MoveCursor(1, 1)
for _, row := range clock.GetOutput() {
tm.Print(row + "\033[K\n")
}
tm.Print("\033[K\n")
for _, row := range weather.GetOutput() {
tm.Print(row + "\033[K\n")
}
tm.Print("\033[K\n")
for _, row := range pollen.GetOutput() {
tm.Print(row + "\033[K\n")
}
tm.Print("\033[K\n")
for _, row := range sl.GetOutput() {
tm.Print(row + "\033[K\n")
}
tm.Print("\033[J")
tm.Flush()
time.Sleep(time.Second / 10)
}
}
func getConfig(configFile string) Config {
var config Config
// Read the configfile
file, err := ioutil.ReadFile(configFile)
if err != nil {
fmt.Printf("File error: %v\n", err)
os.Exit(1)
}
// Parse config
if _, err := toml.Decode(string(file), &config); err != nil {
fmt.Printf("Config error: %v\n", err)
os.Exit(1)
}
return config
}