organizing the code a bit better

This commit is contained in:
2026-06-09 14:51:11 +01:00
parent 99a4f794c5
commit d3c4464aa0
2 changed files with 25 additions and 21 deletions
+23
View File
@@ -0,0 +1,23 @@
package tviewhelpers
import "github.com/rivo/tview"
func FindNodeByID(node *tview.TreeNode, id int16) *tview.TreeNode {
if node == nil {
return nil
}
if ref, ok := node.GetReference().(int16); ok {
if ref == id {
return node
}
}
for _, child := range node.GetChildren() {
if found := FindNodeByID(child, id); found != nil {
return found
}
}
return nil
}
+2 -21
View File
@@ -5,6 +5,7 @@ import (
"log/slog"
"esdi/cdashdisplay"
tviewh "esdi/tui/internal/tview_helpers"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
@@ -17,26 +18,6 @@ const (
LayoutToolNewWindowID = "new-window-action-form"
)
func FindNodeByID(node *tview.TreeNode, id int16) *tview.TreeNode {
if node == nil {
return nil
}
if ref, ok := node.GetReference().(int16); ok {
if ref == id {
return node
}
}
for _, child := range node.GetChildren() {
if found := FindNodeByID(child, id); found != nil {
return found
}
}
return nil
}
type LayoutTreeView struct {
Tree *tview.TreeView
InputCapture func(*tcell.EventKey) *tcell.EventKey
@@ -199,7 +180,7 @@ func (ltv *LayoutToolView) UpdateFormView(idx int16, win *cdashdisplay.DesktopUI
return
}
node := FindNodeByID(root, idx)
node := tviewh.FindNodeByID(root, idx)
if node == nil {
return
}