| ▲ | chrismorgan 8 hours ago | ||||||||||||||||
There are several quite different things called wcwidth, in part because as a POSIX function it wasn’t well-specified; now I think there are two main families of it, maybe still three; https://wcwidth.readthedocs.io/en/latest/specs.html is the best-specified and -considered of them, but not the most popular. Then there are others that see how wide a character renders, and quantise in some fashion to cell. (This obviously requires knowledge of the font, which should be unavailable to the shell, so it’s a technique only terminals can use.) And in all of these, there are multiple incompatible versions hanging around. The aforelinked one shows some of its changes over time as they wrestle with trying to get things as reasonable as possible, which is fairly obviously hopeless anyway. (Some characters are just too wide, some extremely so, some less so. U+FDFD is generally made 1×1, but it should truly be something like 2×2 or 1×8 or a little wider depending on whether the font employs https://en.wikipedia.org/wiki/Word_heaping. Or the widest Telugu consonant, y, which wants to be 2 columns by itself or 3 or 4 columns with some conjuncts and vowels (e.g. ykuu, య్కూ), but gets squished to one by itself or two in those wider cases.) The terminal emulator must handle a lot of RtL stuff to get it acceptable. In raw mode (where dimensions are knowable) you could almost leave it to the app, but outside raw mode it’s pretty obvious that the terminal has to be BiDi-aware. But even in raw mode, you really can’t treat it as you describe, because Arabic text rendering is rather complex, full of necessary ligatures. | |||||||||||||||||
| ▲ | hnlmorg 7 hours ago | parent [-] | ||||||||||||||||
Unicode defines the width of characters. This is what the POSIX functions like wcwidth refer to. eg https://www.unicode.org/reports/tr11/ So you shouldn't need knowledge of the type-face to know the size of the printed character. If other libraries are printing the characters and then extracting the width from that, then they're doing it wrong and you should look to use a different library instead. The bigger problem I've run into is not different libraries making up their own width assumptions. It's been libraries built against outdated versions of the Unicode standard. > The terminal emulator must handle a lot of RtL stuff to get it acceptable. In raw mode (where dimensions are knowable) you could almost leave it to the app, but outside raw mode it’s pretty obvious that the terminal has to be BiDi-aware. But even in raw mode, you really can’t treat it as you describe, because Arabic text rendering is rather complex, full of necessary ligatures. I think RTL is a distraction from the actual point that we're discussing. But it's worth noting that there are already CSI sequences for enabling RTL behaviour in terminal emulators. It's not something I've personally implemented in my own projects because I have no personal need for it and have had no feature requests from people asking for it who could test the implementation's soundness (unlike Chinese characters, which have seen a reasonable degree of popularity in the projects I've built). But I'm sure some other terminals support it just fine since it was added decades ago as part of ECMA 48. | |||||||||||||||||
| |||||||||||||||||