Skip to content

Commit 08633de

Browse files
committed
Add summary to top of long listing.
1 parent a6ad3d4 commit 08633de

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

format/long.go

+27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414

1515
// Long - Format listing in long format.
1616
func Long(nodes []node.Node) {
17+
displaySummary(nodes)
18+
1719
// populate values
1820
values := make([][]string, len(nodes))
1921
for i := range values {
@@ -49,6 +51,31 @@ func Long(nodes []node.Node) {
4951
}
5052
}
5153

54+
func displaySummary(nodes []node.Node) {
55+
dirCount := 0
56+
dirSize := 0
57+
fileCount := 0
58+
fileSize := 0
59+
for _, node := range nodes {
60+
if node.IsDir {
61+
dirCount++
62+
dirSize += node.Size
63+
} else {
64+
fileCount++
65+
fileSize += node.Size
66+
}
67+
}
68+
fmt.Printf(
69+
"%s (%s @ %s) & %s (%s @ %s)\n",
70+
color.New(color.FgWhite, color.Bold).Sprint("files"),
71+
color.New(color.FgMagenta, color.Bold).Sprint(fileCount),
72+
formatSize(fileSize),
73+
color.New(color.FgWhite, color.Bold).Sprint("directories"),
74+
color.New(color.FgMagenta, color.Bold).Sprint(dirCount),
75+
formatSize(dirSize),
76+
)
77+
}
78+
5279
func extractValues(node node.Node) []string {
5380
return []string{
5481
formatMode(node.Mode),

0 commit comments

Comments
 (0)