gizak / termui

Golang terminal dashboard
MIT License
13.22k stars 786 forks source link

Tree widget #237

Closed namreg closed 5 years ago

namreg commented 5 years ago

Hello, there. I've created a tree widget for my project. I believe this can be useful for anyone else :) Let me know, please, what you think about that.

Thanks for the termui project!

namreg commented 5 years ago

/cc @cjbassi

srlehn commented 5 years ago

screenshot of the example: Auswahl_2019 04 19_12:07:52

cjbassi commented 5 years ago

Thanks for the pr! I'd like to merge this but I'll need some time to look over it and possibly suggest any changes.

namreg commented 5 years ago

@cjbassi

  1. How should the cursor be positioned after collapsing a node? Currently it seems like SelectedRow stays the same, but sometimes that leaves no currently visible node selected. Although that might be fine. Just wanted to get some thoughts.

I did it intentionally. IMHO, cursor position relates to the line in block area, not to the content is rendered to this area. May be I wrong.

  1. Expand and the other functions that operate on self.rows would potentially operate on an incorrect node if a node is added and Expand is called before the tree is rerendered, since self.rows is only updated in Draw. What if we made self.Nodes private and added a SetNodes method that calls prepareNodes? That would also eliminate calling prepareNodes every draw too.

I like the idea to add public method SetNodes and make property rows private. But we can't rid of the prepareNodes calling before render after that because self.rows contains only visible rows (in our case expanded). Hence, I have moved calling of the prepareNodes to every place where self.rows is changing. Please, let me know what you think about that.

namreg commented 5 years ago

gentle ping @cjbassi

cjbassi commented 5 years ago

Apologies for the delay, but I haven't forgotten about this! Currently finishing up the school quarter and I should be able to get to this soon.

namreg commented 5 years ago

No problem) Good luck in the school!

On Sat, 8 Jun 2019 at 01:29, Caleb Bassi notifications@github.com wrote:

Apologies for the delay, but I haven't forgotten about this! Currently finishing up the school quarter and I should be able to get to this soon.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gizak/termui/pull/237?email_source=notifications&email_token=AAC7VQCTB4GANFAKG4F5NKTPZLOLHA5CNFSM4HG547Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXHEVUA#issuecomment-500058832, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC7VQCKD4BKOMW3UL4RWRDPZLOLHANCNFSM4HG547QQ .

cjbassi commented 5 years ago

Sorry for the delay again! Been out of commission a bit due to an injury. I've looked it over again and it LGTM. Changing the widget so that nodes are set with SetNodes looks good. I had to rebase to fix some conflicts but I just merged this and now I'm going to release 3.1. Thanks!

cjbassi commented 5 years ago

I accidentally merged before force pushing the PR which is why it says the PR was closed just btw.