@@ -22,17 +22,18 @@ type model struct {
22
22
toDelete []string
23
23
}
24
24
25
- var (
26
- titleStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("227" )).Bold (true )
25
+ type scanCompleteMsg struct {}
27
26
27
+ var (
28
+ fileStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("255" ))
28
29
selectedFileStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("42" )).Bold (true )
30
+ titleStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("227" )).Bold (true )
29
31
deleteStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("196" )).Bold (true )
30
32
confirmStyle = lipgloss .NewStyle ().Border (lipgloss .RoundedBorder ()).BorderForeground (lipgloss .Color ("196" )).Padding (1 )
31
33
itemStyle = lipgloss .NewStyle ().PaddingLeft (2 )
32
34
selectedStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("42" )).Bold (true )
33
35
errorStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("196" )).Bold (true )
34
-
35
- helpStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("240" )).Italic (true )
36
+ helpStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("240" )).Italic (true )
36
37
)
37
38
38
39
func initialModel (resultsChan <- chan []string ) model {
@@ -114,6 +115,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
114
115
115
116
}
116
117
118
+ case scanCompleteMsg :
119
+ m .scanning = false
120
+ return m , nil
121
+
117
122
case []string :
118
123
m .scanning = false
119
124
m .groups = append (m .groups , msg )
@@ -166,47 +171,53 @@ func (m model) View() string {
166
171
167
172
if m .scanning {
168
173
b .WriteString ("🔍 Scanning for duplicates...\n " )
169
- b .WriteString (helpStyle .Render ("(Press q to quit)\n " ))
170
- return b .String ()
171
- }
172
-
173
- if len (m .groups ) == 0 {
174
+ } else if len (m .groups ) == 0 {
174
175
b .WriteString ("🎉 No duplicates found!\n " )
175
- return b .String ()
176
- }
176
+ } else {
177
+ current := m .groups [m .currentGroup ]
178
+ b .WriteString (fmt .Sprintf (" Group %d/%d (%d files)\n " ,
179
+ m .currentGroup + 1 , len (m .groups ), len (current )))
180
+
181
+ for i , file := range current {
182
+ var line strings.Builder
183
+ if _ , selected := m.selected [m.currentGroup ][i ]; selected {
184
+ line .WriteString (selectedFileStyle .Render ("◉ " ))
185
+ } else {
186
+ line .WriteString ("◌ " )
187
+ }
177
188
178
- current := m .groups [m .currentGroup ]
179
- b .WriteString (fmt .Sprintf (" Group %d/%d (%d files)\n " ,
180
- m .currentGroup + 1 , len (m .groups ), len (current )))
189
+ if i == m .currentFile {
190
+ line .WriteString ("➔ " )
191
+ } else {
192
+ line .WriteString (" " )
193
+ }
181
194
182
- for i , file := range current {
183
- var line strings.Builder
195
+ line .WriteString (fileStyle .Render (file ))
184
196
185
- if _ , selected := m.selected [m.currentGroup ][i ]; selected {
186
- line .WriteString (selectedFileStyle .Render ("◉ " ))
187
- } else {
188
- line .WriteString ("◌ " )
189
- }
197
+ if _ , selected := m.selected [m.currentGroup ][i ]; selected {
198
+ line .WriteString (deleteStyle .Render (" (marked for deletion)" ))
199
+ }
190
200
191
- if i == m .currentFile {
192
- line .WriteString ("➔ " )
193
- } else {
194
- line .WriteString (" " )
201
+ b .WriteString (line .String () + "\n " )
195
202
}
203
+ }
196
204
197
- line .WriteString (selectedFileStyle .Render (file ))
198
-
199
- if _ , selected := m.selected [m.currentGroup ][i ]; selected {
200
- line .WriteString (deleteStyle .Render (" (marked for deletion)" ))
205
+ helpText := ""
206
+ if ! m .showConfirm {
207
+ if m .scanning {
208
+ helpText = helpStyle .Render ("(Press q to quit)" )
209
+ } else if len (m .groups ) > 0 {
210
+ helpText = helpStyle .Render (
211
+ "↑/↓: Navigate files • ←/→: Switch groups • Space: Select • d: Delete selected • q: Quit" ,
212
+ )
213
+ } else {
214
+ helpText = helpStyle .Render ("(Press q to quit)" )
201
215
}
202
-
203
- b .WriteString (line .String () + "\n " )
204
216
}
205
217
206
- help := helpStyle .Render (
207
- "↑/↓: Navigate files • ←/→: Switch groups • Space: Select • d: Delete selected • q: Quit" ,
208
- )
209
- b .WriteString ("\n " + help )
218
+ if helpText != "" {
219
+ b .WriteString ("\n \n " + helpText )
220
+ }
210
221
211
222
return b .String ()
212
223
}
@@ -251,10 +262,11 @@ func (m model) removeDeletedFile(path string) {
251
262
252
263
func waitForResults (results <- chan []string ) tea.Cmd {
253
264
return func () tea.Msg {
254
- if group , ok := <- results ; ok {
255
- return group
265
+ group , ok := <- results
266
+ if ! ok {
267
+ return scanCompleteMsg {}
256
268
}
257
- return nil
269
+ return group
258
270
}
259
271
}
260
272
0 commit comments