The open source coding agent.
TypeScript
wip: refactoring tui
adamdottv50ba0b380bbb
diff --git a/cmd/root.go b/cmd/root.goindex ccee60d39e6..f9a55babec5 100644--- a/cmd/root.go+++ b/cmd/root.go@@ -3,7 +3,6 @@ package cmdimport ("context""fmt"- "io""os""sync""time"@@ -15,7 +14,6 @@ import ("github.com/spf13/cobra""github.com/sst/opencode/internal/config""github.com/sst/opencode/internal/logging"- "github.com/sst/opencode/internal/lsp/discovery""github.com/sst/opencode/internal/pubsub""github.com/sst/opencode/internal/tui""github.com/sst/opencode/internal/tui/app"@@ -69,12 +67,6 @@ to assist developers in writing, debugging, and understanding code directly fromreturn err}- // Run LSP auto-discovery- if err := discovery.IntegrateLSPServers(cwd); err != nil {- slog.Warn("Failed to auto-discover LSP servers", "error", err)- // Continue anyway, this is not a fatal error- }-// Create main context for the applicationctx, cancel := context.WithCancel(context.Background())defer cancel()@@ -92,6 +84,18 @@ to assist developers in writing, debugging, and understanding code directly fromtea.WithAltScreen(),)+ evts, err := app.Events.Event(ctx)+ if err != nil {+ slog.Error("Failed to subscribe to events", "error", err)+ return err+ }++ go func() {+ for item := range evts {+ program.Send(item)+ }+ }()+// Setup the subscriptions, this will send services events to the TUIch, cancelSubs := setupSubscriptions(app, ctx)@@ -122,18 +126,6 @@ to assist developers in writing, debugging, and understanding code directly from}}()- evts, err := app.Events.Event(ctx)- if err != nil {- slog.Error("Failed to subscribe to events", "error", err)- return err- }-- go func() {- for item := range evts {- program.Send(item)- }- }()-// Cleanup function for when the program exitscleanup := func() {// Cancel subscriptions first@@ -256,25 +248,6 @@ func Execute() {}}-// checkStdinPipe checks if there's data being piped into stdin-func checkStdinPipe() (string, bool) {- // Check if stdin is not a terminal (i.e., it's being piped)- stat, _ := os.Stdin.Stat()- if (stat.Mode() & os.ModeCharDevice) == 0 {- // Read all data from stdin- data, err := io.ReadAll(os.Stdin)- if err != nil {- return "", false- }-- // If we got data, return it- if len(data) > 0 {- return string(data), true- }- }- return "", false-}-func init() {rootCmd.Flags().BoolP("help", "h", false, "Help")rootCmd.Flags().BoolP("version", "v", false, "Version")diff --git a/internal/tui/tui.go b/internal/tui/tui.goindex 885736ddc61..ed207b70444 100644--- a/internal/tui/tui.go+++ b/internal/tui/tui.go@@ -16,7 +16,6 @@ import ("github.com/sst/opencode/internal/message""github.com/sst/opencode/internal/permission""github.com/sst/opencode/internal/pubsub"- "github.com/sst/opencode/internal/session""github.com/sst/opencode/internal/status""github.com/sst/opencode/internal/tui/components/chat""github.com/sst/opencode/internal/tui/components/core"@@ -194,6 +193,26 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {case spinner.TickMsg:return a.updateAllPages(msg)+ case client.EventSessionUpdated:+ if msg.Properties.Info.Id == a.app.Session.Id {+ a.app.Session = &msg.Properties.Info+ return a.updateAllPages(state.StateUpdatedMsg{State: nil})+ }++ case client.EventMessageUpdated:+ if msg.Properties.Info.Metadata.SessionID == a.app.Session.Id {+ for i, m := range a.app.Messages {+ if m.Id == msg.Properties.Info.Id {+ a.app.Messages[i] = msg.Properties.Info+ slog.Debug("Updated message", "message", msg.Properties.Info)+ return a.updateAllPages(state.StateUpdatedMsg{State: nil})+ }+ }+ a.app.Messages = append(a.app.Messages, msg.Properties.Info)+ slog.Debug("Appended message", "message", msg.Properties.Info)+ return a.updateAllPages(state.StateUpdatedMsg{State: nil})+ }+case tea.WindowSizeMsg:msg.Height -= 2 // Make space for the status bara.width, a.height = msg.Width, msg.Height@@ -259,34 +278,6 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {a.app.CurrentSessionOLD = msgreturn a.updateAllPages(msg)- case pubsub.Event[session.Session]:- if msg.Type == session.EventSessionUpdated {- if a.app.CurrentSessionOLD.ID == msg.Payload.ID {- a.app.CurrentSessionOLD = &msg.Payload- }- }-- case client.EventMessageUpdated:- if msg.Properties.Info.Metadata.SessionID == a.app.Session.Id {- for i, m := range a.app.Messages {- if m.Id == msg.Properties.Info.Id {- a.app.Messages[i] = msg.Properties.Info- slog.Debug("Updated message", "message", msg.Properties.Info)- return a.updateAllPages(state.StateUpdatedMsg{State: nil})- }- }-- a.app.Messages = append(a.app.Messages, msg.Properties.Info)- slog.Debug("Appended message", "message", msg.Properties.Info)- return a.updateAllPages(state.StateUpdatedMsg{State: nil})- }-- case client.EventSessionUpdated:- if msg.Properties.Info.Id == a.app.Session.Id {- a.app.Session = &msg.Properties.Info- return a.updateAllPages(state.StateUpdatedMsg{State: nil})- }-case dialog.CloseQuitMsg:a.showQuit = falsereturn a, nil