statusscreen/statusscreen.go

66 lines
1.1 KiB
Go
Raw Normal View History

2017-10-15 09:41:36 +02:00
package main
import (
"fmt"
"github.com/BurntSushi/toml"
tm "github.com/buger/goterm"
2017-10-15 09:41:36 +02:00
"io/ioutil"
"os"
"statusscreen"
2017-11-04 14:36:01 +01:00
"time"
2017-10-15 09:41:36 +02:00
)
func main() {
config := getConfig("status.toml")
sl := statusscreen.SL{Config: &config}
2017-11-04 14:36:01 +01:00
clock := statusscreen.Clock{Config: &config}
weather := statusscreen.Weather{Config: &config}
tm.Clear()
2017-11-04 22:09:53 +01:00
tm.Print("\033[?25l")
2017-11-04 14:36:01 +01:00
for {
tm.MoveCursor(1, 1)
2017-11-04 14:36:01 +01:00
for _, row := range clock.GetOutput() {
tm.Print(row + "\033[K\n")
2017-11-04 14:36:01 +01:00
}
tm.Print("\033[K\n")
2017-11-04 14:36:01 +01:00
for _, row := range weather.GetOutput() {
tm.Print(row + "\033[K\n")
2017-11-04 14:36:01 +01:00
}
tm.Print("\033[K\n")
2017-11-04 14:36:01 +01:00
for _, row := range sl.GetOutput() {
tm.Print(row + "\033[K\n")
2017-11-04 14:36:01 +01:00
}
tm.Flush()
2017-11-04 22:09:53 +01:00
time.Sleep(time.Second / 10)
2017-11-04 14:36:01 +01:00
}
2017-10-15 09:41:36 +02:00
}
func getConfig(configFile string) statusscreen.Config {
var config statusscreen.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
}