mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-07 11:54:59 -04:00
Initial UI
This commit is contained in:
24
cmd/main.go
24
cmd/main.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -8,15 +9,14 @@ import (
|
||||
|
||||
"github.com/AmanTahiliani/box-box/internal/api"
|
||||
"github.com/AmanTahiliani/box-box/internal/ui"
|
||||
"github.com/AmanTahiliani/box-box/internal/web"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Redirect all log output to a file so it never pollutes the TUI.
|
||||
if f, err := os.OpenFile("box-box.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644); err == nil {
|
||||
log.SetOutput(f)
|
||||
defer f.Close()
|
||||
}
|
||||
webMode := flag.Bool("web", false, "Start web companion server instead of TUI")
|
||||
port := flag.Int("port", 8080, "Port for web server (used with --web)")
|
||||
flag.Parse()
|
||||
|
||||
var client *api.OpenF1Client
|
||||
if apiKey := os.Getenv("OPENF1_API_KEY"); apiKey != "" {
|
||||
@@ -29,6 +29,20 @@ func main() {
|
||||
// Clean up old file-based cache (one-time migration).
|
||||
go api.CleanupOldFileCache()
|
||||
|
||||
if *webMode {
|
||||
log.SetOutput(os.Stderr) // web mode logs to stderr, not file
|
||||
fmt.Printf("box-box web → http://localhost:%d\n", *port)
|
||||
srv := web.NewServer(client, *port)
|
||||
log.Fatal(srv.Start())
|
||||
return
|
||||
}
|
||||
|
||||
// TUI mode: redirect logs to file so they don't pollute the terminal.
|
||||
if f, err := os.OpenFile("box-box.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644); err == nil {
|
||||
log.SetOutput(f)
|
||||
defer f.Close()
|
||||
}
|
||||
|
||||
model := ui.NewAppModel(client)
|
||||
|
||||
p := tea.NewProgram(
|
||||
|
||||
Reference in New Issue
Block a user