| 103 | } |
| 104 | |
| 105 | func renderUI(rootNode *widgets.TreeNode) { |
| 106 | // First section: instructions |
| 107 | p := widgets.NewParagraph() |
| 108 | p.Text = `- Press [q] or [Ctrl+C] to quit |
| 109 | - Use [Arrow-Keys] to navigate |
| 110 | - Press [Enter] to expand/collapse |
| 111 | ` |
| 112 | x, y := ui.TerminalDimensions() |
| 113 | p.SetRect(0, 0, x, 5) |
| 114 | p.TextStyle.Fg = ui.ColorWhite |
| 115 | p.BorderStyle.Fg = ui.ColorCyan |
| 116 | |
| 117 | // Second section: the tree |
| 118 | l := widgets.NewTree() |
| 119 | l.TextStyle = ui.NewStyle(ui.ColorYellow) |
| 120 | l.SetNodes(rootNode.Nodes) |
| 121 | l.CollapseAll() |
| 122 | l.SetRect(0, 5, x, y) |
| 123 | |
| 124 | // Printing both sections |
| 125 | ui.Render(p, l) |
| 126 | |
| 127 | uiEvents := ui.PollEvents() |
| 128 | for { |
| 129 | e := <-uiEvents |
| 130 | switch e.ID { |
| 131 | case "q", "<C-c>": |
| 132 | return |
| 133 | case "<Down>": |
| 134 | l.ScrollDown() |
| 135 | case "<Up>": |
| 136 | l.ScrollUp() |
| 137 | case "<Enter>": |
| 138 | l.ToggleExpand() |
| 139 | case "<Resize>": |
| 140 | x, y := ui.TerminalDimensions() |
| 141 | l.SetRect(0, 0, x, y) |
| 142 | } |
| 143 | |
| 144 | ui.Render(l) |
| 145 | } |
| 146 | } |