Skip to content

Commit 0e2a44e

Browse files
committed
add file icon for each folder and tokens count for each file in view
1 parent 34cd5b6 commit 0e2a44e

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

internal/model/view.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"fmt"
55
"path/filepath"
66
"strings"
7+
"os"
78

89
"github.com/charmbracelet/lipgloss"
910
"github.com/epilande/codegrab/internal/ui"
11+
"github.com/epilande/codegrab/internal/utils"
1012
)
1113

1214
func (m Model) View() string {
@@ -227,12 +229,20 @@ func (m *Model) refreshViewportContent() {
227229
rawSuffix := ""
228230
if node.IsDir {
229231
if count := dirSelectedCounts[node.Path]; count > 0 {
230-
rawSuffix = fmt.Sprintf(" [%d]", count)
232+
rawSuffix = fmt.Sprintf(" [%d 📄]", count)
233+
}
234+
} else {
235+
if node.IsDependency {
236+
rawSuffix += " [dep]"
237+
}
238+
if ok, err := utils.IsTextFile(node.Path); ok && err == nil {
239+
if contentBytes, err := os.ReadFile(node.Path); err == nil {
240+
content := string(contentBytes)
241+
tokensEstimate := utils.EstimateTokens(content)
242+
rawSuffix += fmt.Sprintf(" [%d tokens]", tokensEstimate)
243+
}
231244
}
232-
} else if node.IsDependency {
233-
rawSuffix = " [dep]"
234245
}
235-
236246
isCursorLine := i == m.cursor
237247

238248
rendered := ui.StyleFileLine(

0 commit comments

Comments
 (0)