@@ -16,8 +16,6 @@ type Node interface {
16
16
17
17
type node struct {
18
18
file os.FileInfo
19
- name string
20
- size int
21
19
}
22
20
23
21
// Fetch - Fetch nodes in currently directory
@@ -28,16 +26,20 @@ func Fetch() []Node {
28
26
nodes := make ([]Node , len (files ))
29
27
30
28
for i := 0 ; i < len (files ); i ++ {
31
- nodes [i ] = node {files [i ], "" , 0 }
29
+ nodes [i ] = node {files [i ]}
32
30
}
33
31
34
32
return nodes
35
33
}
36
34
37
35
func (n node ) Name () string {
38
- if n .name != "" { return n .name }
39
- n .name = fmt .Sprintf ("%c %s/ " , n .icon (), n .color ()(n .file .Name ()))
40
- return n .name
36
+ return n .color ()(n .name ())
37
+ }
38
+
39
+ func (n node ) name () string {
40
+ suffix := ""
41
+ if n .file .IsDir () { suffix = "/" }
42
+ return fmt .Sprintf ("%c %s%s " , n .icon (), n .file .Name (), suffix )
41
43
}
42
44
43
45
func (n node ) icon () rune {
@@ -46,11 +48,10 @@ func (n node) icon() rune {
46
48
}
47
49
48
50
func (n node ) color () func (a ... interface {}) string {
49
- return color .New (color .FgCyan , color .Bold ).SprintFunc ()
51
+ if n .file .IsDir () { return color .New (color .FgCyan , color .Bold ).SprintFunc () }
52
+ return color .New (color .FgWhite ).SprintFunc ()
50
53
}
51
54
52
55
func (n node ) Size () int {
53
- if n .size != 0 { return n .size }
54
- n .size = len ([]rune (n .Name ()))
55
- return n .size
56
+ return len ([]rune (n .name ()))
56
57
}
0 commit comments