[GH-ISSUE #109] Add support for ASCII trees #85

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

Originally created by @dastergon on GitHub (May 4, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/109

It would be great if there was a widget that wraps the treeprint package and allows nested lists in a tree-like form that can be traversable from the keyboard. Bonus: The ascii tree can have the ability to collapse/shrink the sub-lists.

Example:

.
├── item1
│   ├── sub-item1
│   ├── sub-item2
│   ├── sub-item3
Originally created by @dastergon on GitHub (May 4, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/109 It would be great if there was a widget that wraps the [treeprint package](https://github.com/xlab/treeprint) and allows nested lists in a tree-like form that can be traversable from the keyboard. Bonus: The ascii tree can have the ability to collapse/shrink the sub-lists. Example: ``` . ├── item1 │ ├── sub-item1 │ ├── sub-item2 │ ├── sub-item3 ```
kerem closed this issue 2026-03-04 01:01:49 +03:00
Author
Owner

@rivo commented on GitHub (May 4, 2018):

This doesn't seem too difficult to do. The treeprint package appears to give you a string with the tree in it which you could easily write to a TextView (e.g. using textView.SetText()).

Using TextView regions, you could highlight each item and in combination with SetInputCapture(), you could implement collapse/expand functionality.

I don't see this as a standard class in tview but it doesn't look hard to connect the two packages. So if you need it in your own application, it shouldn't be too much of an effort.

<!-- gh-comment-id:386579997 --> @rivo commented on GitHub (May 4, 2018): This doesn't seem too difficult to do. The `treeprint` package appears to give you a string with the tree in it which you could easily write to a `TextView` (e.g. using `textView.SetText()`). Using `TextView` regions, you could highlight each item and in combination with `SetInputCapture()`, you could implement collapse/expand functionality. I don't see this as a standard class in `tview` but it doesn't look hard to connect the two packages. So if you need it in your own application, it shouldn't be too much of an effort.
Author
Owner

@dastergon commented on GitHub (May 4, 2018):

Hi @rivo,

Thanks for the clarifications, I will attempt to implement this myself. Does TextView support pagination for large texts? Also, is search feasible within the TextView?

<!-- gh-comment-id:386618288 --> @dastergon commented on GitHub (May 4, 2018): Hi @rivo, Thanks for the clarifications, I will attempt to implement this myself. Does TextView support pagination for large texts? Also, is search feasible within the TextView?
Author
Owner

@dastergon commented on GitHub (May 6, 2018):

Hi @rivo,

Is there a way to capture the value of a region? Example: ["0"]foobar[""]. I would like to perform an action on the specific name when I move to that region.

<!-- gh-comment-id:386895591 --> @dastergon commented on GitHub (May 6, 2018): Hi @rivo, Is there a way to capture the value of a region? Example: `["0"]foobar[""]`. I would like to perform an action on the specific name when I move to that region.
Author
Owner

@rivo commented on GitHub (May 8, 2018):

GetRegionText() should do what you're looking for.

For a list of currently highlighted regions, see GetHighlights().

<!-- gh-comment-id:387502699 --> @rivo commented on GitHub (May 8, 2018): [`GetRegionText()`](https://godoc.org/github.com/rivo/tview#TextView.GetRegionText) should do what you're looking for. For a list of currently highlighted regions, see [`GetHighlights()`](https://godoc.org/github.com/rivo/tview#TextView.GetHighlights).
Author
Owner

@dastergon commented on GitHub (May 9, 2018):

Hi @rivo, I checked those functions, but I am unable to work with nested regions ["0a"]["0b"]something[""]. GetHighlights() only recognises the latter ["0b"]. Did I miss anything, or should I open an issue for that?

<!-- gh-comment-id:387770320 --> @dastergon commented on GitHub (May 9, 2018): Hi @rivo, I checked those functions, but I am unable to work with nested regions `["0a"]["0b"]something[""]`. GetHighlights() only recognises the latter `["0b"]`. Did I miss anything, or should I open an issue for that?
Author
Owner

@rivo commented on GitHub (May 12, 2018):

I'm not sure I understand exactly what you are expecting. Regions are not nested. If you start a new region, it automatically ends the previous region. And the special [""] only ends the current region, without starting a new one.

Does this clarify it?

<!-- gh-comment-id:388541227 --> @rivo commented on GitHub (May 12, 2018): I'm not sure I understand exactly what you are expecting. Regions are not nested. If you start a new region, it automatically ends the previous region. And the special `[""]` only ends the current region, without starting a new one. Does this clarify it?
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#85
No description provided.