-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (34 loc) · 1.22 KB
/
main.go
File metadata and controls
44 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"fmt"
"github.com/Digital-Shane/treeview"
"github.com/Digital-Shane/treeview/examples/shared"
)
////////////////////////////////////////////////////////////////////
// Simple Tree Example
////////////////////////////////////////////////////////////////////
func main() {
shared.ClearTerminal()
fmt.Println("Basic Tree With Default Formatting")
// Create nodes representing a basic tree structure
root := shared.CreateBasicTreeNodes()
// Create tree with default options
tree := treeview.NewTree([]*treeview.Node[string]{root}, treeview.WithExpandAll[string]())
// Render the tree to a string & print it
output, _ := tree.Render(context.Background())
fmt.Println(output)
shared.WaitDelayThenClearTerminal(3.5)
// Move focus to the second child and re-render
fmt.Println("Focus moved to second child")
tree.SetFocusedID(context.Background(), root.Children()[0].Children()[0].ID())
output, _ = tree.Render(context.Background())
fmt.Println(output)
shared.WaitDelayThenClearTerminal(3.5)
// Delete focus and re-render
fmt.Println("Focus deleted")
tree.SetFocusedID(context.Background(), "")
output, _ = tree.Render(context.Background())
fmt.Println(output)
shared.WaitDelay(3.5)
}