Skip to content

Commit

Permalink
Add tree display option.
Browse files Browse the repository at this point in the history
Resolves #18
  • Loading branch information
drn committed Nov 29, 2018
1 parent 74a1350 commit c25d00c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions format/tree.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package format

import (
"fmt"
"github.com/drn/nerd-ls/node"
"github.com/drn/nerd-ls/list"
)

// Tree - Format listing in tree format.
func Tree(nodes []node.Node, options map[string]int) {
for _, node := range nodes {
prefix := ""
if options["prefix"] == 1 { prefix = "-" }
fmt.Printf("%s%s\n", prefix, nodeColor(node).Sprint(node.Name))
if node.IsDir {
nodes := list.Fetch(node.Name, options)
Tree(nodes, options)
}
}
}
1 change: 1 addition & 0 deletions options/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Options struct {
All bool `short:"a" long:"all" description:"Include directory entries whose names begin with a dot (.)"`
Long bool `short:"l" long:"long" description:"List in long format"`
Icon bool `short:"i" long:"icon" description:"Display nerd-font icons"`
Tree bool `short:"T" long:"tree" description:"Recurse into directories as a tree"`
}

// Parse - Converts flags to string -> int map
Expand Down

0 comments on commit c25d00c

Please sign in to comment.