-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): add testable examples for Hide and SetHidden
- Loading branch information
Showing
2 changed files
with
119 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package tree_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/lipgloss/tree" | ||
) | ||
|
||
// Leaf Examples | ||
|
||
func ExampleLeaf_SetHidden() { | ||
tr := tree.New(). | ||
Child( | ||
"Foo", | ||
tree.Root("Bar"). | ||
Child( | ||
"Qux", | ||
tree.Root("Quux"). | ||
Child("Hello!"), | ||
"Quuux", | ||
), | ||
"Baz", | ||
) | ||
|
||
tr.Children().At(1).Children().At(2).SetHidden(true) | ||
fmt.Println(tr.String()) | ||
// Output: | ||
// | ||
// βββ Foo | ||
// βββ Bar | ||
// β βββ Qux | ||
// β βββ Quux | ||
// β βββ Hello! | ||
// βββ Baz | ||
// | ||
} | ||
|
||
func ExampleNewLeaf() { | ||
tr := tree.New(). | ||
Child( | ||
"Foo", | ||
tree.Root("Bar"). | ||
Child( | ||
"Qux", | ||
tree.Root("Quux"). | ||
Child( | ||
tree.NewLeaf("This should be hidden", true), | ||
tree.NewLeaf( | ||
tree.Root("I am groot").Child("leaves"), false), | ||
), | ||
"Quuux", | ||
), | ||
"Baz", | ||
) | ||
|
||
fmt.Println(tr.String()) | ||
// Output: | ||
// βββ Foo | ||
// βββ Bar | ||
// β βββ Qux | ||
// β βββ Quux | ||
// β β βββ I am groot | ||
// β β βββ leaves | ||
// β βββ Quuux | ||
// βββ Baz | ||
// | ||
} | ||
|
||
// Tree Examples | ||
|
||
func ExampleTree_Hide() { | ||
tr := tree.New(). | ||
Child( | ||
"Foo", | ||
tree.Root("Bar"). | ||
Child( | ||
"Qux", | ||
tree.Root("Quux"). | ||
Child("Foo", "Bar"). | ||
Hide(true), | ||
"Quuux", | ||
), | ||
"Baz", | ||
) | ||
|
||
fmt.Println(tr.String()) | ||
// Output: | ||
// βββ Foo | ||
// βββ Bar | ||
// β βββ Qux | ||
// β βββ Quuux | ||
// βββ Baz | ||
} | ||
|
||
func ExampleTree_SetHidden() { | ||
tr := tree.New(). | ||
Child( | ||
"Foo", | ||
tree.Root("Bar"). | ||
Child( | ||
"Qux", | ||
tree.Root("Quux"). | ||
Child("Foo", "Bar"), | ||
"Quuux", | ||
), | ||
"Baz", | ||
) | ||
|
||
// Hide a tree after its creation. We'll hide Quux. | ||
tr.Children().At(1).Children().At(1).SetHidden(true) | ||
// Output: | ||
// βββ Foo | ||
// βββ Bar | ||
// β βββ Qux | ||
// β βββ Quuux | ||
// βββ Baz | ||
// | ||
fmt.Println(tr.String()) | ||
} |
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