jquast / wcwidth

Python library that measures the width of unicode strings rendered to a terminal
Other
392 stars 58 forks source link

Should wcwidth provide rjust, ljust, center and textwrap? #93

Open jquast opened 10 months ago

jquast commented 10 months ago

In the readme, we talk about the example of writing our own custom rjust function. If the most common use case is text alignment, let's just offer it as a public API. They would be the same name and signature as python's,

And text-wrapping interface,

I have previously added support of these (with terminal sequences) in blessed, https://github.com/jquast/blessed/blob/a34c6b1869b4dd467c6d1ab6895872bb72db7e0f/blessed/sequences.py#L141-L239

dscrofts commented 10 months ago

Definitely! I have implemented the ljust function as per the readme but it would be super convenient to have this already included.

jquast commented 2 months ago

On textwrap, there is a pretty strange edge-case found in downstream blessed library https://github.com/jquast/blessed/pull/275 -- what should be done when wrapping wide characters to a column length of 1? We have no choice but to flow beyond column width. A width of "1" may not even be allowed, or allowed with caveats.

We must also be very careful not to split ZWJ and VS-16 sequences apart.