mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #1104] [Feature Request] ScrollView Widget/Primitive #802
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#802
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ossenthusiast on GitHub (Jul 20, 2025).
Original GitHub issue: https://github.com/rivo/tview/issues/1104
Add a new
tview.Primitivethat is a scrollable list oftview.Primitives.@ossenthusiast commented on GitHub (Jul 21, 2025):
Do you still maintain this? @rivo
@rivo commented on GitHub (Jul 21, 2025):
Yes. Please be patient.
@rivo commented on GitHub (Jul 21, 2025):
Also, I'm not sure what you mean by "scrollable list of
Primitives". You might want to elaborate. With examples, if possible.@ossenthusiast commented on GitHub (Jul 21, 2025):
Sorry for the mention. I mean basically a scrollable horizontal layout (list) of widgets.
@rivo commented on GitHub (Aug 27, 2025):
Flexis basically that. But it's not scrollable. The question with these suggestions is: How would you control the scrolling? Let's say one of the contained elements is aTextAreaand the user is currently entering text. Which keys would you assign to scrolling theFlex?@ossenthusiast commented on GitHub (Aug 27, 2025):
Thanks for the response! I am aware of
Flex, but fundamentally, a flexbox is not meant to be scrollable. This is whereScrollViewcomes in. This is a very common requirement by a lot of TUI applications: you want to display a list of "messages" that the user can perform "actions" on (delete, edit, etc.). Regarding navigation, I would recommend following traditional vim-like keybindings for autocomplete menu:Ctrl+P = Focus Previous
Ctrl+N = Focus Next
@ossenthusiast commented on GitHub (Aug 28, 2025):
Alternatively, you could just expose two methods
FocusPreviousandFocusNext, which the user can use to set an input capture callback themselves for navigation instead of handling defaults. Furthermore, if you don't like the above approach, you could also accept extra arguments in the constructor ofScrollView(NewScrollView) primitive: focusNextKey and focusPreviousKey, both are of typetcell.EventKey:@rivo commented on GitHub (Aug 28, 2025):
Actually, the main problem is not so much the navigation itself — I'd argue that you can do this today by removing/adding items from a
Flexas needed, resulting in a scroll-by-flex-row effect — but that, as mentioned many times in other issues, primitives don't propagate their optimal size upwards. In a chat application, there are some longer messages and some shorter ones. It is currently not possible to size aFlex's child primitive so it fits its contents optimally and there are no plans to introduce this. (This is quite a difficult problem to solve anyway.)The question for such apps is also, why would you need to add any primitive to such a layout?
FlexorGridare primarily aimed at placing interactive controls on the screen, like input fields, checkboxes, buttons, text areas, etc. It strikes me that a chat application is mostly about formatting a long list of text messages, rather than placing interactive controls on screen. Instead of placing dozens or hundreds of smallTextViewelements into aFlex, it may make more sense to put them all into oneTextView, a primitive which is specifically made to display large amounts of text (and it's scrollable, too). It's also flexible in terms of text size: If there is more text, it will expand to more lines automatically.I get that at this point, formatting messages in a
TextViewfor a chat/messages app may be difficult. But I would think that this is a problem that can be solved a lot more easily than inventing a new container primitive. (I seem to recall an issue asking for something like this but I cannot find it right now.)@rivo commented on GitHub (Sep 4, 2025):
FYI, I added a very simple chat application which illustrates how you might deal with flexible paragraphs:
https://github.com/rivo/tview/tree/master/demos/textview/chat
@ossenthusiast commented on GitHub (Sep 4, 2025):
Thanks! A common thing chat apps have is being able to select a "message" and perform certain actions on it (delete, edit, etc, navigate using keys, etc), how would you implement that while being performant? For example, I have used region IDs and highlights to mimic that behavior in my chat TUI for Matrix, but to update a single message, I would have to remove the message and then redraw everything to TextView, which is pretty slow. This has been a pretty major pain-point for me with tview. Looking forward to your thoughts on this!
@ossenthusiast commented on GitHub (Sep 4, 2025):
BTW, the chat demo uses the
(*tview.TextView).GetRegionsfunction, which does not exist.@rivo commented on GitHub (Sep 4, 2025):
It does for me:
github.com/rivo/tview@4cdaaa9bd6/textview.go (L823)