gitstack

grindlemire/go-tui code browser

690 B Go 37 lines 2026-02-27 · 9f8e903 raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Package main demonstrates the Building a Dashboard guide example.
//
// To build and run:
//
//	go run ../../cmd/tui generate dashboard.gsx
//	go run .
package main

import (
	"fmt"
	"os"

	tui "github.com/grindlemire/go-tui"
)

//go:generate go run ../../cmd/tui generate dashboard.gsx

func main() {
	eventCh := make(chan string, 100)

	app, err := tui.NewApp(
		tui.WithRootComponent(Dashboard(eventCh)),
		tui.WithMouse(),
	)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create app: %v\n", err)
		os.Exit(1)
	}
	defer app.Close()

	go produceEvents(eventCh, app.StopCh())

	if err := app.Run(); err != nil {
		fmt.Fprintf(os.Stderr, "App error: %v\n", err)
		os.Exit(1)
	}
}