-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
184 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ddddddO/gtree" | ||
) | ||
|
||
func main() { | ||
root := gtree.NewRoot("root") | ||
root.Add("child 1").Add("child 2").Add("child 3") | ||
root.Add("child 4") | ||
if err := gtree.ExecuteProgrammably(root, os.Stdout); err != nil { | ||
panic(err) | ||
} | ||
|
||
// root | ||
// ├── child 1 | ||
// │ └── child 2 | ||
// │ └── child 3 | ||
// └── child 4 | ||
|
||
fmt.Println("-----") | ||
|
||
// https://ja.wikipedia.org/wiki/%E3%82%B5%E3%83%AB%E7%9B%AE | ||
primate := gtree.NewRoot("Primate") | ||
|
||
strepsirrhini := primate.Add("Strepsirrhini") | ||
haplorrhini := primate.Add("Haplorrhini") | ||
|
||
_ = strepsirrhini.Add("Lemuriformes") | ||
_ = strepsirrhini.Add("Lorisiformes") | ||
|
||
_ = haplorrhini.Add("Tarsiiformes") | ||
_ = haplorrhini.Add("Simiiformes") | ||
if err := gtree.ExecuteProgrammably(primate, os.Stdout); err != nil { | ||
panic(err) | ||
} | ||
|
||
// root | ||
// ├── child 1 | ||
// │ └── child 2 | ||
// │ └── child 3 | ||
// └── child 4 | ||
// ----- | ||
// Primate | ||
// ├── Strepsirrhini | ||
// │ ├── Lemuriformes | ||
// │ └── Lorisiformes | ||
// └── Haplorrhini | ||
// ├── Tarsiiformes | ||
// └── Simiiformes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gtree | ||
|
||
import "io" | ||
|
||
// TODO: 命名がイマイチ | ||
func ExecuteProgrammably(root *node, w io.Writer) error { | ||
tree := &tree{ | ||
roots: []*node{root}, | ||
lastNodeFormat: lastNodeFormat{ | ||
directly: "└──", | ||
indirectly: " ", | ||
}, | ||
intermedialNodeFormat: intermedialNodeFormat{ | ||
directly: "├──", | ||
indirectly: "│ ", | ||
}, | ||
} | ||
|
||
tree.grow() | ||
return tree.expand(w) | ||
} | ||
|
||
var programableNodeIdx int | ||
|
||
func NewRoot(name string) *node { | ||
programableNodeIdx++ | ||
|
||
return newNode(name, rootHierarchyNum, programableNodeIdx) | ||
} | ||
|
||
func (current *node) Add(name string) *node { | ||
programableNodeIdx++ | ||
|
||
n := newNode(name, current.hierarchy+1, programableNodeIdx) | ||
n.parent = current | ||
current.children = append(current.children, n) | ||
return n | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
- ## Description | ||
- CLI or Package. | ||
- Given a markdown file or format, the result of the tree command is printed. | ||
- `gtree` does not temporarily create directories or files. | ||
- Create markdown file by referring to the file in the `testdata/` directory. | ||
- Hierarchy is represented by indentation. | ||
- Indentation should be unified by one of the following. | ||
- Tab | ||
- Two half-width spaces(required: `-ts`) | ||
- Four half-width spaces(required: `-fs`) | ||
- CLI and Package(1). | ||
- Given a markdown file or format, the result of the tree command is printed. | ||
- `gtree` does not temporarily create directories or files. | ||
- Create markdown file by referring to the file in the `testdata/` directory. | ||
- Hierarchy is represented by indentation. | ||
- Indentation should be unified by one of the following. | ||
- Tab | ||
- Two half-width spaces(required: `-ts`) | ||
- Four half-width spaces(required: `-fs`) | ||
- Package(2). | ||
- You can also generate a tree programmatically. | ||
- Markdown is irrelevant. |