summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorPetri Hienonen <petri.hienonen@gmail.com>2026-02-01 22:15:14 +0200
committerPetri Hienonen <petri.hienonen@gmail.com>2026-02-01 22:15:14 +0200
commit50541ca317e2ae647fc83d25e38825bb5a120296 (patch)
tree16bb87964a1809a83bb69db8ac69e12f457862b5 /main.go
parentb99d904cd2b37feb129a6d747d1ce422d31cffba (diff)
downloadweather-50541ca317e2ae647fc83d25e38825bb5a120296.tar.zst
Add initial TUI
Diffstat (limited to 'main.go')
-rw-r--r--main.go52
1 files changed, 43 insertions, 9 deletions
diff --git a/main.go b/main.go
index c5008be..268f8f9 100644
--- a/main.go
+++ b/main.go
@@ -1,4 +1,4 @@
-// main.go - Main application entry point
+// main.go - Main application
package main
import (
@@ -6,13 +6,22 @@ import (
"flag"
"fmt"
"os"
+ "os/signal"
+ "syscall"
+ "time"
)
func main() {
- location := flag.String("place", "Helsinki", "Location for the forecast")
+ var (
+ location = flag.String("place", "Helsinki", "Location for the forecast")
+ tuiMode = flag.Bool("tui", true, "Run in TUI mode")
+ jsonMode = flag.Bool("json", false, "Output as JSON")
+ days = flag.Int("days", 1, "Number of days to forecast (1-3)")
+ refresh = flag.Int("refresh", 0, "Refresh interval in minutes (0 for no refresh)")
+ )
flag.Parse()
- // Create client and get forecast
+ // Get initial forecast
client := NewFMIClient()
response, err := client.GetForecast(*location)
if err != nil {
@@ -20,11 +29,36 @@ func main() {
os.Exit(1)
}
- // Output JSON
- jsonData, err := json.MarshalIndent(response, "", " ")
- if err != nil {
- fmt.Fprintf(os.Stderr, "Error marshaling JSON: %v\n", err)
- os.Exit(1)
+ // JSON output mode
+ if *jsonMode {
+ jsonData, err := json.MarshalIndent(response, "", " ")
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error marshaling JSON: %v\n", err)
+ os.Exit(1)
+ }
+ fmt.Println(string(jsonData))
+ return
+ }
+
+ // TUI mode
+ if *tuiMode {
+ model := NewModel(response, *location, *days)
+ if *refresh > 0 {
+ model.SetRefreshInterval(time.Duration(*refresh) * time.Minute)
+ }
+
+ // Handle interrupts
+ sigChan := make(chan os.Signal, 1)
+ signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+ go func() {
+ <-sigChan
+ model.Quit()
+ }()
+
+ // Run the TUI
+ if err := model.Run(); err != nil {
+ fmt.Fprintf(os.Stderr, "Error running TUI: %v\n", err)
+ os.Exit(1)
+ }
}
- fmt.Println(string(jsonData))
}