aboutsummaryrefslogtreecommitdiff
path: root/internal/app/state.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/app/state.go')
-rw-r--r--internal/app/state.go114
1 files changed, 114 insertions, 0 deletions
diff --git a/internal/app/state.go b/internal/app/state.go
new file mode 100644
index 0000000..82e186d
--- /dev/null
+++ b/internal/app/state.go
@@ -0,0 +1,114 @@
+package app
+
+import (
+ "strings"
+ "time"
+
+ "github.com/Fuwn/faustus/internal/claude"
+)
+
+func (m *Model) updateFiltered() {
+ query := strings.ToLower(m.searchInput.Value())
+ m.filtered = nil
+
+ for _, session := range m.sessions {
+ if m.tab == TabTrash && !session.InTrash {
+ continue
+ }
+
+ if m.tab == TabSessions && session.InTrash {
+ continue
+ }
+
+ if query != "" {
+ searchable := strings.ToLower(session.Summary + " " + session.FirstPrompt + " " + session.ProjectName + " " + session.GitBranch)
+
+ if !strings.Contains(searchable, query) {
+ continue
+ }
+ }
+
+ m.filtered = append(m.filtered, session)
+ }
+
+ if m.cursor >= len(m.filtered) {
+ m.cursor = max(0, len(m.filtered)-1)
+ }
+}
+
+func (m *Model) setMessage(statusMessage string) {
+ m.message = statusMessage
+ m.messageTime = time.Now()
+}
+
+func (m *Model) selectedSession() *claude.Session {
+ if m.cursor >= 0 && m.cursor < len(m.filtered) {
+ sessionID := m.filtered[m.cursor].SessionID
+
+ for index := range m.sessions {
+ if m.sessions[index].SessionID == sessionID {
+ return &m.sessions[index]
+ }
+ }
+ }
+
+ return nil
+}
+
+func (m *Model) updateFilteredFromOriginal() {
+ if m.cursor >= 0 && m.cursor < len(m.filtered) {
+ sessionID := m.filtered[m.cursor].SessionID
+
+ for _, session := range m.sessions {
+ if session.SessionID == sessionID {
+ m.filtered[m.cursor] = session
+
+ break
+ }
+ }
+ }
+}
+
+func (m *Model) reloadSessions() {
+ sessions, loadError := claude.LoadAllSessions()
+
+ if loadError == nil {
+ m.sessions = sessions
+
+ m.updateFiltered()
+ }
+}
+
+func (m *Model) ensureVisible() {
+ visibleHeight := m.listHeight()
+
+ if m.cursor < m.offset {
+ m.offset = m.cursor
+ }
+
+ if m.cursor >= m.offset+visibleHeight {
+ m.offset = m.cursor - visibleHeight + 1
+ }
+}
+
+func (m Model) listWidth() int {
+ if m.showPreview {
+ return m.width / 2
+ }
+
+ return m.width
+}
+
+func (m Model) previewWidth() int {
+ return m.width - m.listWidth() - 3
+}
+
+func (m Model) listHeight() int {
+ reserved := 8
+
+ if m.showHelp {
+ reserved += 12
+ }
+
+ return max(1, m.height-reserved)
+}