timber

command module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2023 License: MIT Imports: 3 Imported by: 0

README

timber

About

Printing an ASCII tree with Go(education purpose).

Thanks to https://github.com/Tufin/asciitree for the idea

Example of ASCII tree:

|- root1
| |- sibling1
| |- sibling2
|    |- sibling1
|    |- sibling2
|- root2
   |- sibling1
   |- sibling2

Usage

func main() {
	tree := timber_example.Branch{
		Label: "branch",
		Items: []timber_interface.NodeTree{
			timber_example.Leaf{
				Label: "leaf",
			},
			timber_example.Branch{
				Label: "branch",
				Items: []timber_interface.NodeTree{
					timber_example.Leaf{
						Label: "leaf",
					},
					timber_example.Leaf{
						Label: "leaf",
					},
					timber_example.Leaf{
						Label: "leaf",
					},
				},
			},
			timber_example.Leaf{
				Label: "leaf",
			},
		},
	}
	printer := timber.NewDefaultPrinter()
	printer.Print(tree)
}

will output

INFO[0000] └ branch                                     
INFO[0000]  ├ leaf                                      
INFO[0000]  ├ branch                                    
INFO[0000]  │ ├ leaf                                    
INFO[0000]  │ ├ leaf                                    
INFO[0000]  │ └ leaf                                    
INFO[0000]  └ leaf   

If a custom printer function or result aggergater function is needed, use:

func NewCustomPrinter(printerFn PrinterFn, result interface{}, resultFn ResultFn) *customPrinter

Installation

Prequisite
$ go version
go version go1.20 linux/amd64
Command

go get github.com/leetcode-golang-classroom/timber

Contributing

Please free to fork, create a branch and open a pull request.

License

This is under MIT License.

Contact

Please contact:

LINKEDIN

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL