summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/tui/cmd/opencode/main.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/packages/tui/cmd/opencode/main.go b/packages/tui/cmd/opencode/main.go
index 2f079cfab..a0b2a3768 100644
--- a/packages/tui/cmd/opencode/main.go
+++ b/packages/tui/cmd/opencode/main.go
@@ -5,7 +5,9 @@ import (
"encoding/json"
"log/slog"
"os"
+ "os/signal"
"strings"
+ "syscall"
tea "github.com/charmbracelet/bubbletea/v2"
flag "github.com/spf13/pflag"
@@ -81,6 +83,10 @@ func main() {
tea.WithMouseCellMotion(),
)
+ // Set up signal handling for graceful shutdown
+ sigChan := make(chan os.Signal, 1)
+ signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
+
go func() {
stream := httpClient.Event.ListStreaming(ctx)
for stream.Next() {
@@ -93,6 +99,13 @@ func main() {
}
}()
+ // Handle signals in a separate goroutine
+ go func() {
+ sig := <-sigChan
+ slog.Info("Received signal, shutting down gracefully", "signal", sig)
+ program.Quit()
+ }()
+
// Run the TUI
result, err := program.Run()
if err != nil {