Skip to content

Commit 618f7f9

Browse files
committed
refactor
1 parent eb1786c commit 618f7f9

File tree

4 files changed

+356
-176
lines changed

4 files changed

+356
-176
lines changed

app/app.go

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app
22

33
import (
4+
"claude-squad/app/controller"
45
"claude-squad/config"
56
"claude-squad/keys"
67
"claude-squad/session"
@@ -47,7 +48,7 @@ type home struct {
4748
// state is the current discrete state of the app
4849
state tuiState
4950
// controller manages instances and orchestrators
50-
controller *controller
51+
controller *controller.Controller
5152
// program is the program to use for instances and orchestrators
5253
program string
5354
// autoYes is whether to automatically approve actions
@@ -97,11 +98,13 @@ func newHome(ctx context.Context, program string, autoYes bool) *home {
9798
appState: appState,
9899
}
99100

100-
controller := newController(&h.spinner, h.autoYes)
101-
if err := controller.LoadExistingInstances(h); err != nil {
101+
// Initialize controller with spinner and autoYes setting
102+
ctrl := controller.NewController(&h.spinner, h.autoYes)
103+
// Pass home object which implements required interfaces
104+
if err := ctrl.LoadExistingInstances(h); err != nil {
102105
fmt.Printf("Warning: Failed to load existing instances: %v\n", err)
103106
}
104-
h.controller = controller
107+
h.controller = ctrl
105108

106109
return h
107110
}
@@ -127,8 +130,9 @@ func (m *home) updateHandleWindowSizeEvent(msg tea.WindowSizeMsg) {
127130
listWidth := int(float32(msg.Width) * 0.4)
128131
previewWidth := msg.Width - listWidth
129132

130-
m.controller.list.SetSize(listWidth, contentHeight)
131-
m.controller.tabbedWindow.SetSize(previewWidth, contentHeight)
133+
// Access controller's UI components via exported fields or methods
134+
m.controller.SetListSize(listWidth, contentHeight)
135+
m.controller.SetTabbedWindowSize(previewWidth, contentHeight)
132136
}
133137

134138
func (m *home) Init() tea.Cmd {
@@ -145,14 +149,63 @@ func (m *home) Init() tea.Cmd {
145149
}
146150

147151
func (m *home) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
148-
return m.controller.Update(m, msg)
152+
_, cmd := m.controller.Update(m, msg)
153+
return m, cmd
149154
}
150155

151156
func (m *home) handleQuit() (tea.Model, tea.Cmd) {
152-
m.controller.HandleQuit(m)
157+
// We ignore the returned model since we're returning ourselves
158+
_, _ = m.controller.HandleQuit(m)
153159
return m, tea.Quit
154160
}
155161

162+
// Helper methods to support controller functionality
163+
164+
// GetStorage returns the storage instance
165+
func (m *home) GetStorage() *session.Storage {
166+
return m.storage
167+
}
168+
169+
// GetMenu returns the menu instance
170+
func (m *home) GetMenu() *ui.Menu {
171+
return m.menu
172+
}
173+
174+
// GetErrBox returns the error box instance
175+
func (m *home) GetErrBox() *ui.ErrBox {
176+
return m.errBox
177+
}
178+
179+
// GetState returns the current UI state
180+
func (m *home) GetState() tuiState {
181+
return m.state
182+
}
183+
184+
// SetState sets the UI state
185+
func (m *home) SetState(state tuiState) {
186+
m.state = state
187+
}
188+
189+
// GetProgram returns the program name
190+
func (m *home) GetProgram() string {
191+
return m.program
192+
}
193+
194+
// GetAutoYes returns the autoYes flag
195+
func (m *home) GetAutoYes() bool {
196+
return m.autoYes
197+
}
198+
199+
// GetSpinner returns the spinner instance
200+
func (m *home) GetSpinner() *spinner.Model {
201+
return &m.spinner
202+
}
203+
204+
// UpdateSpinner updates the spinner model
205+
func (m *home) UpdateSpinner(msg spinner.TickMsg) (spinner.Model, tea.Cmd) {
206+
return m.spinner.Update(msg)
207+
}
208+
156209
func (m *home) handleMenuHighlighting(msg tea.KeyMsg) (cmd tea.Cmd, returnEarly bool) {
157210
// Handle menu highlighting when you press a button. We intercept it here and immediately return to
158211
// update the ui while re-sending the keypress. Then, on the next call to this, we actually handle the keypress.

0 commit comments

Comments
 (0)