summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-03-21 18:20:28 +0100
committerKujtim Hoxha <[email protected]>2025-03-21 18:20:28 +0100
commit4b0ea68d7af9a6031a7ffda7ad66e0cb83315750 (patch)
tree8220c1bf6f107ea76dd78c7f57b77000c0c98a22 /cmd
downloadopencode-4b0ea68d7af9a6031a7ffda7ad66e0cb83315750.tar.gz
opencode-4b0ea68d7af9a6031a7ffda7ad66e0cb83315750.zip
initial
Diffstat (limited to 'cmd')
-rw-r--r--cmd/termai/main.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/cmd/termai/main.go b/cmd/termai/main.go
new file mode 100644
index 000000000..5b71728d8
--- /dev/null
+++ b/cmd/termai/main.go
@@ -0,0 +1,59 @@
+package main
+
+import (
+ "context"
+ "sync"
+
+ tea "github.com/charmbracelet/bubbletea"
+ "github.com/kujtimiihoxha/termai/internal/logging"
+ "github.com/kujtimiihoxha/termai/internal/tui"
+)
+
+var log = logging.Get()
+
+func main() {
+ log.Info("Starting termai...")
+ ctx := context.Background()
+
+ app := tea.NewProgram(
+ tui.New(),
+ tea.WithAltScreen(),
+ )
+ log.Info("Setting up subscriptions...")
+ ch, unsub := setupSubscriptions(ctx)
+ defer unsub()
+
+ go func() {
+ for msg := range ch {
+ app.Send(msg)
+ }
+ }()
+ if _, err := app.Run(); err != nil {
+ panic(err)
+ }
+}
+
+func setupSubscriptions(ctx context.Context) (chan tea.Msg, func()) {
+ ch := make(chan tea.Msg)
+ wg := sync.WaitGroup{}
+ ctx, cancel := context.WithCancel(ctx)
+
+ {
+ sub := log.Subscribe(ctx)
+ wg.Add(1)
+ go func() {
+ for ev := range sub {
+ ch <- ev
+ }
+ wg.Done()
+ }()
+ }
+ // cleanup function to be invoked when program is terminated.
+ return ch, func() {
+ cancel()
+ // Wait for relays to finish before closing channel, to avoid sends
+ // to a closed channel, which would result in a panic.
+ wg.Wait()
+ close(ch)
+ }
+}