Skip to content

Commit 081e3c2

Browse files
committed
Node style adjustments and remove memoization.
1 parent 77985fe commit 081e3c2

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

node/root.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ type Node interface {
1616

1717
type node struct {
1818
file os.FileInfo
19-
name string
20-
size int
2119
}
2220

2321
// Fetch - Fetch nodes in currently directory
@@ -28,16 +26,20 @@ func Fetch() []Node {
2826
nodes := make([]Node, len(files))
2927

3028
for i:=0; i<len(files); i++ {
31-
nodes[i] = node{files[i], "", 0}
29+
nodes[i] = node{files[i]}
3230
}
3331

3432
return nodes
3533
}
3634

3735
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)
4143
}
4244

4345
func (n node) icon() rune {
@@ -46,11 +48,10 @@ func (n node) icon() rune {
4648
}
4749

4850
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()
5053
}
5154

5255
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()))
5657
}

0 commit comments

Comments
 (0)