MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / DepTree

Function DepTree

cmd/ui/ui.go:140–170  ·  view source on GitHub ↗
(report format.Report)

Source from the content-addressed store, hash-verified

138}
139
140func DepTree(report format.Report) *tview.TreeView {
141
142 var root *tview.TreeNode
143 if report.DepDetailGraph != nil && report.DepDetailGraph.Name != "" {
144 root = newTreeNode(report.DepDetailGraph)
145 } else {
146 root = tview.NewTreeNode(report.TaskInfo.AppName).SetColor(colorPath)
147 }
148
149 depTreeRoot := report.DepDetailGraph
150 depTreeRoot.Expand = root
151
152 tree := tview.NewTreeView().SetRoot(root).SetCurrentNode(root)
153 tree.SetSelectedFunc(func(node *tview.TreeNode) {
154 if len(node.GetChildren()) > 0 {
155 node.SetExpanded(!node.IsExpanded())
156 }
157 })
158
159 depTreeRoot.ForEach(func(n *detail.DepDetailGraph) bool {
160 node := n.Expand.(*tview.TreeNode)
161 for _, c := range n.Children {
162 sub := newTreeNode(c)
163 c.Expand = sub
164 node.AddChild(sub)
165 }
166 return true
167 })
168
169 return tree
170}
171
172func newTreeNode(d *detail.DepDetailGraph) *tview.TreeNode {
173

Callers 1

OpenUIFunction · 0.85

Calls 2

newTreeNodeFunction · 0.85
ForEachMethod · 0.45

Tested by

no test coverage detected