ratatui-org / ratatui

Rust library that's all about cooking up terminal user interfaces (TUIs) 👨‍🍳🐀
https://ratatui.rs
MIT License
8.82k stars 263 forks source link

Add option to wrap depending on length of line, not last space character #1199

Open michirakara opened 1 week ago

michirakara commented 1 week ago

Problem

In Asian and many other languages, we usually don't put spaces between words, but we put spaces between words when there are numbers or alphabets. (for example: 私は ratatui が本当に便利だと思います) When I use wrap feature in ratatui, this sentence would look like this.

私は ratatui            |
が本当に便利だと思います  |

However, we usually change line not depending on spaces, and only depending on length of line, so it should look like

私は ratatui が本当に便利|
だと思います             |

Solution

Add option to ratatui::widgets::Paragraph::wrap or ratatui::widgets::Wrap so that it doesn't care about spaces and only changes line when characters overflow from a line.

Alternatives

N/A

Additional context

N/A

joshka commented 1 week ago

There's a pretty long issue that we haven't really progressed on recently for defining how to wrap properly. https://github.com/ratatui-org/ratatui/issues/293. This fits in the "Support Character and Word boundaries" function I think.

I'd suggest as an immediate workaround to pre-wrap your text as needed. Consider whether the textwrap crate works for your use case. You could probably easily

QQ: How would you expect wrapping to work if the wrap point was in the middle of the ratatui word in the above case?

michirakara commented 1 week ago

Thanks for the resource to textwrap crate! That worked for my case. By the way, it is expected to wrap to new line at the beginning of word "ratatui", but considering type of characters might be too complicated for a simple feature. For temporaly solution, just linking textwrap crate on docs could be useful for users.

joshka commented 1 week ago

For temporaly solution, just linking textwrap crate on docs could be useful for users.

Good idea :)