blob: cebd672850793cfa777ed9aa85e3335ec7e9a318 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
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.setMessage("Reload error: " + loadError.Error())
return
}
m.sessions = sessions
m.updateFiltered()
m.invalidatePreviewCache()
if m.cursor >= len(m.filtered) {
m.cursor = max(0, len(m.filtered)-1)
}
}
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)
}
|