diff options
| author | adamdotdevin <[email protected]> | 2025-07-10 15:58:55 -0500 |
|---|---|---|
| committer | adamdotdevin <[email protected]> | 2025-07-10 15:59:03 -0500 |
| commit | 85805d2c38d0c2e4ddbdc749b5404f316b209c90 (patch) | |
| tree | 651386524c94f8f274dc379ca701bfd4c619d480 | |
| parent | 982cb3e71ada9b5efc917257ef0dcf5237c34565 (diff) | |
| download | opencode-85805d2c38d0c2e4ddbdc749b5404f316b209c90.tar.gz opencode-85805d2c38d0c2e4ddbdc749b5404f316b209c90.zip | |
fix(tui): handle SIGTERM, closes #319
| -rw-r--r-- | packages/tui/cmd/opencode/main.go | 13 |
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 { |
