[GH-ISSUE #246] The .Walk() functionality on a tree view always returns the parent as nil #191

Closed
opened 2026-03-04 01:02:49 +03:00 by kerem · 2 comments
Owner

Originally created by @thebsdbox on GitHub (Mar 4, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/246

Unless I'm doing this wrong I don't seem to be able to walk up the tree, I'm trying to find the parent with the reference I'm expecting.

Example below, I need to be able to walk the pre-boot Snapshot up the tree to it's parent with the expected reference virtual machine which maps to a VM named server05 where I can then perform the expected action.

│  ├──server05                                                                                                                                                 
│  │  ├──Details                                                                                                                                               
│  │  │  ├──CPUs: 1                                                                                                                                            
│  │  │  ├──Memory: 1024                                                                                                                                       
│  │  │  ├──Type: Ubuntu Linux (64-bit)                                                                                                                        
│  │  │  ├──VMware Tools: toolsNotInstalled                                                                                                                    
│  │  │  ├──VM IP Address:                                                                                                                                     
│  │  │  └──MAC ADDRESS: 00:50:56:A3:91:EE                                                                                                                     
│  │  └──Snapshots                                                                                                                                             
│  │     └──pre-boot    
Originally created by @thebsdbox on GitHub (Mar 4, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/246 Unless I'm doing this wrong I don't seem to be able to walk up the tree, I'm trying to find the parent with the reference I'm expecting. Example below, I need to be able to walk the `pre-boot` Snapshot up the tree to it's parent with the expected reference `virtual machine` which maps to a VM named `server05` where I can then perform the expected action. ``` │ ├──server05 │ │ ├──Details │ │ │ ├──CPUs: 1 │ │ │ ├──Memory: 1024 │ │ │ ├──Type: Ubuntu Linux (64-bit) │ │ │ ├──VMware Tools: toolsNotInstalled │ │ │ ├──VM IP Address: │ │ │ └──MAC ADDRESS: 00:50:56:A3:91:EE │ │ └──Snapshots │ │ └──pre-boot ```
kerem closed this issue 2026-03-04 01:02:49 +03:00
Author
Owner

@thebsdbox commented on GitHub (Mar 5, 2019):

Ended up using a struct that carries a pointer back to the VM and pinning it to child nodes with SetReference(v), I presume thats the way to go. (works for me :) )

<!-- gh-comment-id:469693293 --> @thebsdbox commented on GitHub (Mar 5, 2019): Ended up using a struct that carries a pointer back to the VM and pinning it to child nodes with `SetReference(v)`, I presume thats the way to go. (works for me :) )
Author
Owner

@rivo commented on GitHub (Mar 9, 2019):

Internally, tree nodes do not keep a reference to their parents, only to their children, i.e. top-down. The TreeNode class gives you a lot of freedom to call SetChildren() or AddChild() anywhere and I didn't want to get into the mess of keeping children and parents in sync. (I'm not even sure if this is possible, e.g. if you use the same TreeNode multiple times.)

The only way to access a parent within tview is to use the Walk() function and then it's only temporary and returns nil for the node you call Walk() on (see documentation). You'd have to call Walk() on the root node (which may be inefficient for your case).

So yeah, you'll have to resort to keeping a reference to the parent by yourself, as you do.

I'll close this for now. If you want to keep the discussion going, we can always reopen this issue.

<!-- gh-comment-id:471173854 --> @rivo commented on GitHub (Mar 9, 2019): Internally, tree nodes do not keep a reference to their parents, only to their children, i.e. top-down. The `TreeNode` class gives you a lot of freedom to call `SetChildren()` or `AddChild()` anywhere and I didn't want to get into the mess of keeping children and parents in sync. (I'm not even sure if this is possible, e.g. if you use the same `TreeNode` multiple times.) The only way to access a parent within `tview` is to use the `Walk()` function and then it's only temporary and returns `nil` for the node you call `Walk()` on (see documentation). You'd have to call `Walk()` on the root node (which may be inefficient for your case). So yeah, you'll have to resort to keeping a reference to the parent by yourself, as you do. I'll close this for now. If you want to keep the discussion going, we can always reopen this issue.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#191
No description provided.