@@ -2,6 +2,7 @@ package format
2
2
3
3
import (
4
4
"fmt"
5
+ "math"
5
6
"regexp"
6
7
"strings"
7
8
"strconv"
@@ -25,8 +26,8 @@ func Long(nodes []node.Node) {
25
26
formatMode (node .Mode ),
26
27
strconv .Itoa (node .LinkCount ),
27
28
fmt .Sprintf ("%s " , node .User ),
28
- fmt .Sprintf ("%s " , node .Group ),
29
- humanize .Bytes (node .Size ),
29
+ fmt .Sprintf ("%s " , node .Group ),
30
+ colorSize ( node . Size , humanize .Bytes (node .Size ) ),
30
31
node .Time .Month ().String ()[:3 ],
31
32
fmt .Sprintf ("%2d" , node .Time .Day ()),
32
33
fmt .Sprintf ("%02d:%02d" , node .Time .Hour (), node .Time .Minute ()),
@@ -63,6 +64,21 @@ func Long(nodes []node.Node) {
63
64
}
64
65
}
65
66
67
+ func colorSize (sizeInt int , str string ) string {
68
+ size := float64 (sizeInt )
69
+ base := float64 (1024 )
70
+ // less than 1K
71
+ if size < base { return str }
72
+ // less than 10M
73
+ if size < math .Pow (base , 2 ) * 10 { return color .GreenString (str ) }
74
+ // less than 100M
75
+ if size < math .Pow (base , 2 ) * 100 { return color .YellowString (str ) }
76
+ // less than 1G
77
+ if size < math .Pow (base , 3 ) { return color .RedString (str ) }
78
+ // above 1G
79
+ return color .New (color .FgRed , color .Bold ).Sprint (str )
80
+ }
81
+
66
82
// strips ANSI color codes from string
67
83
func strip (str string ) string {
68
84
return ansiRegex .ReplaceAllString (str , "" )
@@ -72,7 +88,7 @@ func formatMode(mode string) string {
72
88
runes := []rune (mode )
73
89
74
90
return fmt .Sprintf (
75
- "%s%s%s%s%s%s%s%s%s%s" ,
91
+ "%s%s%s%s%s%s%s%s%s%s " ,
76
92
colorize (runes [0 ], color .New (color .FgWhite , color .Bold )),
77
93
colorize (runes [1 ], color .New (color .FgGreen )),
78
94
colorize (runes [2 ], color .New (color .FgGreen )),
0 commit comments