|
|
|
|
|
by hnlmorg
25 days ago
|
|
It might seem unsound but it’s the concept we’ve built our terminals around. And there are already definitions and APIs to decide the terminal cell width of different Unicode characters. I’m not saying it’s easy, because you end up with 3 different string widths: 1. memory length in bytes 2. Number of Unicode characters (which is annoyingly also different to the number of Unicode code points since some codes can be combined) 3. terminal cell width But as annoying as it is, there are a few relatively mature libraries you can use to solve this problem. |
|
And how! I know of four different and mutually-incompatible definitions/behaviours, and I’m confident there will be more; and once you get to things like Indic scripts and Right-to-Left there are no good answers, and no cell-based terminal produces even vaguely acceptable results.
As for meanings of string width, I’d count at least four: Unicode code units, Unicode scalar values, Unicode extended grapheme clusters, and terminal cells.