Open staehle opened 1 month ago
+1 from me, sounds like it might be a good addition to the viewport.
It would be nice if, for example, there was an additional insert_before_wrap that did not take a height arg and simply calculated it based on the contents, e.g.:
The problem with this is that widgets don't have any inherent height. They fill / fit in the available space. For the Paragraph widget we added a line_count
method that can be used to calculate the number of lines that paragraph will use to render given a known width.
Doing this more generically for every widget is a much bigger problem and a fundamental change to how widgets work. Effectively it requires all widgets to have some say in how they are laid out, rather than this being something passed into the widgets. This is a good idea in a general sense, but not one to implement on this method. I'm exploring some ideas in https://github.com/joshka/tui-brulee for using taffy to lay out widgets, but they're in a very early stage.
Problem
Hello! This is just a suggestion -- I have a workaround in my code, but perhaps native support for this could be nice?
There doesn't seem to be native support for line wrapping +
insert_before
in a viewport. For example:If, given a terminal wide enough, I would have output like:
However, on smaller-width terminals, this would instead truncate that line to fit the
height
argument of 1, which is not what I would expect given my "wrap" call (but is however understandable why it does this):Solution
It would be nice if, for example, there was an additional
insert_before_wrap
that did not take aheight
arg and simply calculated it based on the contents, e.g.:Alternatives
My workaround for this is that I needed to manually calculate if the line I'm
insert_before
'ing would wrap given the current terminal width, and then increase theheight
arg appropriately if so. e.g.:This would produce this output if the terminal width (80 here) was less than the outputted line:
or say 50 width:
This is fine, but I need to do this for every
insert_before
that might have long lines that I still want the user to see.Thanks!