Skip to content

Commit a4c25fc

Browse files
authoredMar 9, 2025··
Merge pull request #3 from sig-seg-v13/fix-scanning-blocking-issue-when-no-files-are-detected-in-interactive-mode
fix: properly return `no duplicates found` when no duplicate files are detected
2 parents 15ecb92 + ef3f1ee commit a4c25fc

File tree

1 file changed

+50
-38
lines changed

1 file changed

+50
-38
lines changed
 

‎model.go

+50-38
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ type model struct {
2222
toDelete []string
2323
}
2424

25-
var (
26-
titleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("227")).Bold(true)
25+
type scanCompleteMsg struct{}
2726

27+
var (
28+
fileStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("255"))
2829
selectedFileStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).Bold(true)
30+
titleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("227")).Bold(true)
2931
deleteStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("196")).Bold(true)
3032
confirmStyle = lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("196")).Padding(1)
3133
itemStyle = lipgloss.NewStyle().PaddingLeft(2)
3234
selectedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).Bold(true)
3335
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)
3637
)
3738

3839
func initialModel(resultsChan <-chan []string) model {
@@ -114,6 +115,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
114115

115116
}
116117

118+
case scanCompleteMsg:
119+
m.scanning = false
120+
return m, nil
121+
117122
case []string:
118123
m.scanning = false
119124
m.groups = append(m.groups, msg)
@@ -166,47 +171,53 @@ func (m model) View() string {
166171

167172
if m.scanning {
168173
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 {
174175
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+
}
177188

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+
}
181194

182-
for i, file := range current {
183-
var line strings.Builder
195+
line.WriteString(fileStyle.Render(file))
184196

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+
}
190200

191-
if i == m.currentFile {
192-
line.WriteString("➔ ")
193-
} else {
194-
line.WriteString(" ")
201+
b.WriteString(line.String() + "\n")
195202
}
203+
}
196204

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)")
201215
}
202-
203-
b.WriteString(line.String() + "\n")
204216
}
205217

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+
}
210221

211222
return b.String()
212223
}
@@ -251,10 +262,11 @@ func (m model) removeDeletedFile(path string) {
251262

252263
func waitForResults(results <-chan []string) tea.Cmd {
253264
return func() tea.Msg {
254-
if group, ok := <-results; ok {
255-
return group
265+
group, ok := <-results
266+
if !ok {
267+
return scanCompleteMsg{}
256268
}
257-
return nil
269+
return group
258270
}
259271
}
260272

0 commit comments

Comments
 (0)
Please sign in to comment.