diff --git a/internal/ui/dialog/dialog.go b/internal/ui/dialog/dialog.go index ec9472dc892c1a095abb284897966ac92b259dc4..2796ea16a78b24e0349ac30f1a4485271deae51e 100644 --- a/internal/ui/dialog/dialog.go +++ b/internal/ui/dialog/dialog.go @@ -33,14 +33,6 @@ func NewOverlay(dialogs ...Dialog) *Overlay { } } -// IsFrontDialog checks if the dialog with the specified ID is at the front. -func (d *Overlay) IsFrontDialog(dialogID string) bool { - if len(d.dialogs) == 0 { - return false - } - return d.dialogs[len(d.dialogs)-1].ID() == dialogID -} - // HasDialogs checks if there are any active dialogs. func (d *Overlay) HasDialogs() bool { return len(d.dialogs) > 0 @@ -56,13 +48,13 @@ func (d *Overlay) ContainsDialog(dialogID string) bool { return false } -// AddDialog adds a new dialog to the stack. -func (d *Overlay) AddDialog(dialog Dialog) { +// OpenDialog opens a new dialog to the stack. +func (d *Overlay) OpenDialog(dialog Dialog) { d.dialogs = append(d.dialogs, dialog) } -// RemoveDialog removes the dialog with the specified ID from the stack. -func (d *Overlay) RemoveDialog(dialogID string) { +// CloseDialog closes the dialog with the specified ID from the stack. +func (d *Overlay) CloseDialog(dialogID string) { for i, dialog := range d.dialogs { if dialog.ID() == dialogID { d.removeDialog(i) @@ -71,8 +63,8 @@ func (d *Overlay) RemoveDialog(dialogID string) { } } -// RemoveFrontDialog removes the front dialog from the stack. -func (d *Overlay) RemoveFrontDialog() { +// CloseFrontDialog closes the front dialog in the stack. +func (d *Overlay) CloseFrontDialog() { if len(d.dialogs) == 0 { return } diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index fac8ccd7f1813c1f839a34bee28c6bfcd6bdc0b0..713dfb1a33f4338dc0e436e585815696bbcc9dd2 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -193,7 +193,7 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { sessions := dialog.NewSessions(m.com, msg.sessions...) // TODO: Get. Rid. Of. Magic numbers! sessions.SetSize(min(120, m.width-8), 30) - m.dialog.AddDialog(sessions) + m.dialog.OpenDialog(sessions) case sessionLoadedMsg: m.state = uiChat m.session = &msg.sess @@ -357,7 +357,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) { switch { case key.Matches(msg, m.keyMap.Quit): if !m.dialog.ContainsDialog(dialog.QuitID) { - m.dialog.AddDialog(dialog.NewQuit(m.com)) + m.dialog.OpenDialog(dialog.NewQuit(m.com)) return true } } @@ -388,7 +388,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) { } else { // TODO: Get. Rid. Of. Magic numbers! commands.SetSize(min(120, m.width-8), 30) - m.dialog.AddDialog(commands) + m.dialog.OpenDialog(commands) } } case key.Matches(msg, m.keyMap.Models): @@ -419,10 +419,10 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) { switch msg := msg.(type) { // Generic dialog messages case dialog.CloseMsg: - m.dialog.RemoveFrontDialog() + m.dialog.CloseFrontDialog() // Session dialog messages case dialog.SessionSelectedMsg: - m.dialog.RemoveDialog(dialog.SessionsID) + m.dialog.CloseDialog(dialog.SessionsID) cmds = append(cmds, m.loadSession(msg.Session.ID), m.loadSessionFiles(msg.Session.ID), @@ -430,10 +430,10 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) { // Command dialog messages case dialog.ToggleYoloModeMsg: m.com.App.Permissions.SetSkipRequests(!m.com.App.Permissions.SkipRequests()) - m.dialog.RemoveDialog(dialog.CommandsID) + m.dialog.CloseDialog(dialog.CommandsID) case dialog.SwitchSessionsMsg: cmds = append(cmds, m.loadSessionsCmd) - m.dialog.RemoveDialog(dialog.CommandsID) + m.dialog.CloseDialog(dialog.CommandsID) case dialog.CompactMsg: err := m.com.App.AgentCoordinator.Summarize(context.Background(), msg.SessionID) if err != nil { @@ -441,7 +441,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) { } case dialog.ToggleHelpMsg: m.help.ShowAll = !m.help.ShowAll - m.dialog.RemoveDialog(dialog.CommandsID) + m.dialog.CloseDialog(dialog.CommandsID) case dialog.QuitMsg: cmds = append(cmds, tea.Quit) }