Skip to content

Commit 42a1e0b

Browse files
nrjdalalclaude
andcommitted
feat: show folder sizes in interactive tree
Folder sizes calculated from sum of children. Shown right-aligned same as file sizes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e2c17e4 commit 42a1e0b

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

bin/utils/interactive-picker.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ function buildTree(entries: TreeEntry[]): TreeNode[] {
101101
}
102102
sortChildren(root)
103103

104+
// Calculate folder sizes from children
105+
function calcSize(nodes: TreeNode[]): number {
106+
let total = 0
107+
for (const node of nodes) {
108+
if (node.children.length) {
109+
node.size = calcSize(node.children)
110+
}
111+
total += node.size
112+
}
113+
return total
114+
}
115+
calcSize(root)
116+
104117
return root
105118
}
106119

@@ -364,7 +377,7 @@ export function interactivePicker(
364377
const pointer = isCursor ? yellow(">") : " "
365378
const leftPart = `${pointer} ${checkbox} ${dim(item.prefix)}${dim(item.connector)}${expandIcon}${nameStr}`
366379
const sizeLabel =
367-
item.node.type === "blob" && item.node.size > 0 ? dim(formatSize(item.node.size)) : ""
380+
item.node.size > 0 && item.node.type !== "symlink" ? dim(formatSize(item.node.size)) : ""
368381
const leftLen = stripAnsi(leftPart).length
369382
const sizeLen = stripAnsi(sizeLabel).length
370383
const gap = Math.max(1, cols - leftLen - sizeLen - 1)

0 commit comments

Comments
 (0)