mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 02:02:37 +02:00
add tree view
This commit is contained in:
parent
d1814742fa
commit
a325243047
@ -8,6 +8,7 @@ import (
|
|||||||
type Tree interface {
|
type Tree interface {
|
||||||
AddNode(string) Tree
|
AddNode(string) Tree
|
||||||
FlatView() chan string
|
FlatView() chan string
|
||||||
|
TreeView() chan string
|
||||||
}
|
}
|
||||||
|
|
||||||
type node struct {
|
type node struct {
|
||||||
@ -51,3 +52,38 @@ func (t *node) FlatView() (out chan string) {
|
|||||||
}()
|
}()
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *node) TreeView() (out chan string) {
|
||||||
|
out = make(chan string)
|
||||||
|
treeLinkChar := "│ "
|
||||||
|
treeMidChar := "├── "
|
||||||
|
treeEndChar := "└── "
|
||||||
|
treeAfterEndChar := " "
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer close(out)
|
||||||
|
|
||||||
|
var tree func(string, *node)
|
||||||
|
|
||||||
|
tree = func(prefix string, t *node) {
|
||||||
|
for i, st := range t.Children {
|
||||||
|
switch i {
|
||||||
|
case len(t.Children) - 1:
|
||||||
|
out <- prefix + treeEndChar + st.Name
|
||||||
|
tree(prefix+treeAfterEndChar, st)
|
||||||
|
case 0:
|
||||||
|
out <- prefix + treeMidChar + st.Name
|
||||||
|
tree(prefix+treeLinkChar, st)
|
||||||
|
default:
|
||||||
|
out <- prefix + treeMidChar + st.Name
|
||||||
|
tree(prefix+treeLinkChar, st)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out <- t.Name
|
||||||
|
tree("", t)
|
||||||
|
|
||||||
|
}()
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
@ -114,66 +114,15 @@ func (c *ImagesListCommand) Execute(args []string) error {
|
|||||||
}
|
}
|
||||||
bar.Close()
|
bar.Close()
|
||||||
|
|
||||||
results := rootTree.FlatView()
|
var results chan string
|
||||||
|
if c.Tree {
|
||||||
|
results = rootTree.TreeView()
|
||||||
|
} else {
|
||||||
|
results = rootTree.FlatView()
|
||||||
|
}
|
||||||
for filename := range results {
|
for filename := range results {
|
||||||
fmt.Println(filename)
|
fmt.Println(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort.Strings(results)
|
|
||||||
|
|
||||||
// if !c.Tree {
|
|
||||||
// for _, r := range results {
|
|
||||||
// fmt.Println(r)
|
|
||||||
// }
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// type Tree struct {
|
|
||||||
// Name string
|
|
||||||
// Children []*Tree
|
|
||||||
// }
|
|
||||||
|
|
||||||
// treeMap := make(map[string]*Tree)
|
|
||||||
// treeMap[""] = &Tree{Name: "."}
|
|
||||||
|
|
||||||
// for _, r := range results {
|
|
||||||
// parentpath := ""
|
|
||||||
// fullpath := ""
|
|
||||||
// for _, s := range strings.Split(r, "/") {
|
|
||||||
// parentpath = fullpath
|
|
||||||
// fullpath += s + "/"
|
|
||||||
// if _, ok := treeMap[fullpath]; ok {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// treeMap[fullpath] = &Tree{Name: s}
|
|
||||||
// treeMap[parentpath].Children = append(treeMap[parentpath].Children, treeMap[fullpath])
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var treeView func(*Tree, string)
|
|
||||||
// treeLinkChar := "│ "
|
|
||||||
// treeMidChar := "├── "
|
|
||||||
// treeEndChar := "└── "
|
|
||||||
// treeAfterEndChar := " "
|
|
||||||
|
|
||||||
// treeView = func(t *Tree, prefix string) {
|
|
||||||
// for i, st := range t.Children {
|
|
||||||
// switch i {
|
|
||||||
// case len(t.Children) - 1:
|
|
||||||
// fmt.Println(prefix + treeEndChar + st.Name)
|
|
||||||
// treeView(st, prefix+treeAfterEndChar)
|
|
||||||
// case 0:
|
|
||||||
// fmt.Println(prefix + treeMidChar + st.Name)
|
|
||||||
// treeView(st, prefix+treeLinkChar)
|
|
||||||
// default:
|
|
||||||
// fmt.Println(prefix + treeMidChar + st.Name)
|
|
||||||
// treeView(st, prefix+treeLinkChar)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fmt.Println(treeMap[""].Name)
|
|
||||||
// treeView(treeMap[""], "")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user