Open iphydf opened 2 years ago
More problematic is the case where the width of a character is greater than 1. E.g.
Resizing the terminal so wrapping should occur:
Resizing it a bit more so wrapping actually does occur (but incorrectly, because part of the text is still clipped at the edge):
Thanks for filing this. It's true that I didn't consider character width when I wrote this, and that came much later in Vty and Brick. In addition to not considering width at all, the problem is even worse: even if this library did consider widths (which require a sophisticated lookahead system), the terminals themselves frequently do not all agree on the widths of the printed results. This problem has made it very difficult to make any guarantees that e.g. Vty will come to the same conclusion about glyph width because the terminal emulators themselves also have internal lookup tables to know how many terminal cells will be occupied by the printed characters. Those tables are often wrong or very, very stale. And Vty has its own internal table (in the C sources) that is also old. When we attempted to update it, it actually made layout behaviors worse on terminal emulators that then came into greater disagreement with Vty as a result!
With all that said, if the more general problem of Unicode width measurement in Vty is something you have any interest in working on and helping to advance, I would be delighted to get your help. As far as this library is concerned, it would face similar problems: what version of the lookup tables to use, how to deal (or not) with terminal disagreements, and what to do about sophisticated Unicode-aware lookahead.
This library has surprising behaviour for text where a single glyph is made of several code points, e.g. in Korean (Hangul) where ᄁ + ᅪ = 꽈, which is the same as 꽈, but the former has 2 code points while the latter has 1. This is also a problem for other types of combiner characters like "<̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊>̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊̊", which is a somewhat pathological case but helps as a test case to write a fix against. Wrapping to e.g. 10 columns, I would expect the following text
to become
but in fact,
word-wrap
turns it intoReproducer: