on main help sign in
refactor(ui): dialog: rename Add/Remove to Open/Close
e24c9c3Ayman Bagabas
internal/ui/dialog/dialog.go+6−14
@@ -33,14 +33,6 @@ func NewOverlay(dialogs ...Dialog) *Overlay {
33 }
33 }
34}
34}
35
35
36−// IsFrontDialog checks if the dialog with the specified ID is at the front.
37−func (d *Overlay) IsFrontDialog(dialogID string) bool {
38− if len(d.dialogs) == 0 {
39− return false
40− }
41− return d.dialogs[len(d.dialogs)-1].ID() == dialogID
42−}
43−
44// HasDialogs checks if there are any active dialogs.
36// HasDialogs checks if there are any active dialogs.
45func (d *Overlay) HasDialogs() bool {
37func (d *Overlay) HasDialogs() bool {
46 return len(d.dialogs) > 0
38 return len(d.dialogs) > 0
@@ -56,13 +48,13 @@ func (d *Overlay) ContainsDialog(dialogID string) bool {
56 return false
48 return false
57}
49}
58
50
59−// AddDialog adds a new dialog to the stack.
51+// OpenDialog opens a new dialog to the stack.
60−func (d *Overlay) AddDialog(dialog Dialog) {
52+func (d *Overlay) OpenDialog(dialog Dialog) {
61 d.dialogs = append(d.dialogs, dialog)
53 d.dialogs = append(d.dialogs, dialog)
62}
54}
63
55
64−// RemoveDialog removes the dialog with the specified ID from the stack.
56+// CloseDialog closes the dialog with the specified ID from the stack.
65−func (d *Overlay) RemoveDialog(dialogID string) {
57+func (d *Overlay) CloseDialog(dialogID string) {
66 for i, dialog := range d.dialogs {
58 for i, dialog := range d.dialogs {
67 if dialog.ID() == dialogID {
59 if dialog.ID() == dialogID {
68 d.removeDialog(i)
60 d.removeDialog(i)
@@ -71,8 +63,8 @@ func (d *Overlay) RemoveDialog(dialogID string) {
71 }
63 }
72}
64}
73
65
74−// RemoveFrontDialog removes the front dialog from the stack.
66+// CloseFrontDialog closes the front dialog in the stack.
75−func (d *Overlay) RemoveFrontDialog() {
67+func (d *Overlay) CloseFrontDialog() {
76 if len(d.dialogs) == 0 {
68 if len(d.dialogs) == 0 {
77 return
69 return
78 }
70 }
internal/ui/model/ui.go+8−8
@@ -193,7 +193,7 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
193 sessions := dialog.NewSessions(m.com, msg.sessions...)
193 sessions := dialog.NewSessions(m.com, msg.sessions...)
194 // TODO: Get. Rid. Of. Magic numbers!
194 // TODO: Get. Rid. Of. Magic numbers!
195 sessions.SetSize(min(120, m.width-8), 30)
195 sessions.SetSize(min(120, m.width-8), 30)
196− m.dialog.AddDialog(sessions)
196+ m.dialog.OpenDialog(sessions)
197 case sessionLoadedMsg:
197 case sessionLoadedMsg:
198 m.state = uiChat
198 m.state = uiChat
199 m.session = &msg.sess
199 m.session = &msg.sess
@@ -357,7 +357,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) {
357 switch {
357 switch {
358 case key.Matches(msg, m.keyMap.Quit):
358 case key.Matches(msg, m.keyMap.Quit):
359 if !m.dialog.ContainsDialog(dialog.QuitID) {
359 if !m.dialog.ContainsDialog(dialog.QuitID) {
360− m.dialog.AddDialog(dialog.NewQuit(m.com))
360+ m.dialog.OpenDialog(dialog.NewQuit(m.com))
361 return true
361 return true
362 }
362 }
363 }
363 }
@@ -388,7 +388,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) {
388 } else {
388 } else {
389 // TODO: Get. Rid. Of. Magic numbers!
389 // TODO: Get. Rid. Of. Magic numbers!
390 commands.SetSize(min(120, m.width-8), 30)
390 commands.SetSize(min(120, m.width-8), 30)
391− m.dialog.AddDialog(commands)
391+ m.dialog.OpenDialog(commands)
392 }
392 }
393 }
393 }
394 case key.Matches(msg, m.keyMap.Models):
394 case key.Matches(msg, m.keyMap.Models):
@@ -419,10 +419,10 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) {
419 switch msg := msg.(type) {
419 switch msg := msg.(type) {
420 // Generic dialog messages
420 // Generic dialog messages
421 case dialog.CloseMsg:
421 case dialog.CloseMsg:
422− m.dialog.RemoveFrontDialog()
422+ m.dialog.CloseFrontDialog()
423 // Session dialog messages
423 // Session dialog messages
424 case dialog.SessionSelectedMsg:
424 case dialog.SessionSelectedMsg:
425− m.dialog.RemoveDialog(dialog.SessionsID)
425+ m.dialog.CloseDialog(dialog.SessionsID)
426 cmds = append(cmds,
426 cmds = append(cmds,
427 m.loadSession(msg.Session.ID),
427 m.loadSession(msg.Session.ID),
428 m.loadSessionFiles(msg.Session.ID),
428 m.loadSessionFiles(msg.Session.ID),
@@ -430,10 +430,10 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) {
430 // Command dialog messages
430 // Command dialog messages
431 case dialog.ToggleYoloModeMsg:
431 case dialog.ToggleYoloModeMsg:
432 m.com.App.Permissions.SetSkipRequests(!m.com.App.Permissions.SkipRequests())
432 m.com.App.Permissions.SetSkipRequests(!m.com.App.Permissions.SkipRequests())
433− m.dialog.RemoveDialog(dialog.CommandsID)
433+ m.dialog.CloseDialog(dialog.CommandsID)
434 case dialog.SwitchSessionsMsg:
434 case dialog.SwitchSessionsMsg:
435 cmds = append(cmds, m.loadSessionsCmd)
435 cmds = append(cmds, m.loadSessionsCmd)
436− m.dialog.RemoveDialog(dialog.CommandsID)
436+ m.dialog.CloseDialog(dialog.CommandsID)
437 case dialog.CompactMsg:
437 case dialog.CompactMsg:
438 err := m.com.App.AgentCoordinator.Summarize(context.Background(), msg.SessionID)
438 err := m.com.App.AgentCoordinator.Summarize(context.Background(), msg.SessionID)
439 if err != nil {
439 if err != nil {
@@ -441,7 +441,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) {
441 }
441 }
442 case dialog.ToggleHelpMsg:
442 case dialog.ToggleHelpMsg:
443 m.help.ShowAll = !m.help.ShowAll
443 m.help.ShowAll = !m.help.ShowAll
444− m.dialog.RemoveDialog(dialog.CommandsID)
444+ m.dialog.CloseDialog(dialog.CommandsID)
445 case dialog.QuitMsg:
445 case dialog.QuitMsg:
446 cmds = append(cmds, tea.Quit)
446 cmds = append(cmds, tea.Quit)
447 }
447 }