Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/tui/dialog/session_browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dialog

import (
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -29,6 +30,7 @@ type sessionBrowserKeyMap struct {
Star key.Binding
FilterStar key.Binding
CopyID key.Binding
Delete key.Binding
}

// Session browser dialog dimension constants
Expand Down Expand Up @@ -82,6 +84,7 @@ func NewSessionBrowserDialog(sessions []session.Summary) Dialog {
Star: key.NewBinding(key.WithKeys("ctrl+s")),
FilterStar: key.NewBinding(key.WithKeys("ctrl+f")),
CopyID: key.NewBinding(key.WithKeys("ctrl+y")),
Delete: key.NewBinding(key.WithKeys("ctrl+d")),
},
openedAt: time.Now(),
}
Expand Down Expand Up @@ -195,6 +198,17 @@ func (d *sessionBrowserDialog) Update(msg tea.Msg) (layout.Model, tea.Cmd) {
}
return d, nil

case key.Matches(msg, d.keyMap.Delete):
if d.selected >= 0 && d.selected < len(d.filtered) {
sessionID := d.filtered[d.selected].ID
d.sessions = slices.DeleteFunc(d.sessions, func(s session.Summary) bool {
return s.ID == sessionID
})
d.filterSessions()
return d, core.CmdHandler(messages.DeleteSessionMsg{SessionID: sessionID})
}
return d, nil

default:
var cmd tea.Cmd
d.textInput, cmd = d.textInput.Update(msg)
Expand Down Expand Up @@ -333,7 +347,8 @@ func (d *sessionBrowserDialog) View() string {
AddSeparator().
AddContent(idFooter).
AddSpace().
AddHelpKeys("↑/↓", "navigate", "ctrl+s", "star", "ctrl+f", filterDesc, "ctrl+y", "copy id", "enter", "load", "esc", "close").
AddHelpKeys("↑/↓", "navigate", "ctrl+s", "star", "ctrl+f", filterDesc, "ctrl+y", "copy id", "ctrl+d", "delete").
AddHelpKeys("enter", "load", "esc", "close").
Build()

return styles.DialogStyle.Width(dialogWidth).Render(content)
Expand Down
13 changes: 13 additions & 0 deletions pkg/tui/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ func (m *appModel) handleRegenerateTitle() (tea.Model, tea.Cmd) {
return m, tea.Batch(spinnerCmd, notification.SuccessCmd("Regenerating title..."))
}

func (m *appModel) handleDeleteSession(sessionID string) (tea.Model, tea.Cmd) {
store := m.application.SessionStore()
if store == nil {
return m, notification.ErrorCmd("No session store configured")
}

if err := store.DeleteSession(context.Background(), sessionID); err != nil {
return m, notification.ErrorCmd("Failed to delete session: " + err.Error())
}

return m, notification.SuccessCmd("Session deleted.")
}

func isErrTitleGenerating(err error) bool {
return err != nil && err.Error() == app.ErrTitleGenerating.Error()
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/tui/messages/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type (
// ToggleSessionStarMsg toggles star on a session; empty ID means current session.
ToggleSessionStarMsg struct{ SessionID string }

// DeleteSessionMsg deletes a session by ID.
DeleteSessionMsg struct{ SessionID string }

// SetSessionTitleMsg sets the session title to specified value.
SetSessionTitleMsg struct{ Title string }

Expand Down
3 changes: 3 additions & 0 deletions pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,9 @@ func (m *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return m.handleToggleSessionStar(sessionID)

case messages.DeleteSessionMsg:
return m.handleDeleteSession(msg.SessionID)

case messages.SetSessionTitleMsg:
return m.handleSetSessionTitle(msg.Title)

Expand Down