-
Notifications
You must be signed in to change notification settings - Fork 484
How to scroll Paragraph when appending to the end? #89
Comments
Right now scrolling is pretty much O(n). Paragraph essentially behaves as a pager (e.g. In the text below I only consider text reflow with word wrapping, as of #103 - the case with line truncation cannot be more diffcult anyway. 1. Scroll to the bottom It would be possible to implement a special "scroll to the bottom" mode by storing the last If we make the text iterator double-ended (rather - potentially double-ended), we'd "only" have to keep working our way from the end to the previous 2. Scroll to X% of the text, know how far you've scrolled to from the offset, scrollbars None of the above makes the above easy - for these you have to know the total height of the text (open a large file with Making the text random-access doesn't work for new lines - Text::raw and Text::styled still contain strings, which are not random-access and character widths vary. The extra options I can see:
3. Since Paragraph consumes an iterator of Text reflow would then operate on the flattened Text iterator and Paragraph would consume the result of word wrapping, shifting the logic away from the Paragraph. |
Another TODO when implementing this - make scroll usize rather than u16, possibly add vertical scrolling. |
I'd like to +1 this request. I'm currently working on a fork that will implement some kind of a solution for this problem. Will post in here, and if @fdehau or @karolinepauls thinks its useful, i'm happy to try and clean it up and merge upstream. |
A more elegant solution seemed to be more than I was willing off to attempt in one evening. Spent a lot of time thinking of switching the LineComposer to a streaming iterator, and then possibly a DoubleEndedStreamingIterator... but I ended up just adding a @svenstaro I also added an example in my branch so you can clone & take a look if you want to see how it works and do a similar workaround in your project: https://github.com/clevinson/tui-rs/blob/scroll-from-bottom/examples/paragraph.rs#L93-L99 Happy to continue work on this and clean it up into something more reasonable if you see a preferred path forward.. @karolinepauls |
@fdehau This is now cleaned up, enabling two kinds of "scroll modes":
In the Tail mode of scroll, the
2. Content is longer than text_area
|
I just ran into the lack of this feature while working on a project with this library (trying to use paragraph to display wrapped log output while always displaying the most recent log line at the bottom). It would be super nice to see support for this situation land! EDIT: I ended up pre-wrapping the text with https://github.com/mgeisler/textwrap and just using the list widget to display it. |
Unfortunately doing this manually outside of the tui crate with the Not so bad if you restrict lines to being a single style (but of course I want lines with multiple styles 😛). EDIT: example impl of line wrapping here (with the constraint that lines are built from un-styled strings) |
@clevinson Do you still intent to make a pr on this repo to merge your fix upstream or do you think #349 handles your needs? |
Hi @Cldfire, I'm just guessing, but could it be that the Basically, Textwrap internally wraps such "fragments" which has a width and some trailing whitespace. For plain text, the I recently wrote an example which draws text on a HTML canvas and there I wrap proportional text using a I would be happy to talk more if you think Textwrap could be useful for tui-rs somehow. |
@mgeisler ah that's really neat! It definitely looks like I'm not working on that particular project of mine atm but if I do revisit it at some point in the future I'll definitely try making use of |
I have a long multi-line string that I continuously append onto and I'd like
Paragraph
to append to the end. I'd then likeParagraph
to scroll down so that no lines get hidden from the newly appended text. However, I can't know how much to scroll becauseParagraph
doesn't yield any information about its layouted text.The text was updated successfully, but these errors were encountered: