3 ms·
See also [0] for description of Dart's auto-formatter for how (some) other pretty printers work. P.S. "unicode-width is to get accurate string widths for monos
by Joker_vD 3y ago
See also [0] for description of Dart's auto-formatter for how (some) other pretty printers work.
P.S. "unicode-width is to get accurate string widths for monospaced terminal fonts including full-width Unicode characters. I’m pretty sure this is an impossible problem" ― it's not impossible, it's just that different terminals (and different terminal fonts) have different ideas on the amount of screen cells occupied by the Unicode codepoints and the chances that they will coincide with the ideas of the Unicode library your app uses are pretty slim. For instance, '\N{WOMAN}\N{ZWJ}\N{HEAVY BLACK HEART}\N{VARIATION SELECTOR-16}\N{ZWJ}\N{MAN}' could be either 2 cells if your terminal and font support the single combined 'Couple with Heart: Woman, Man' emoji; or 6 cells if they fall back to displaying it as a sequence of 'Woman', 'Red Heart', 'Man' emojis; or 5 cells if your terminal fails to recognize that '\N{HEAVY BLACK HEART}\N{VARIATION SELECTOR-16}' actually takes 2 cells, not 1: GNOME Terminal 3.28.2 for instance, does that although it still paints the 2-cells wide 'Red Heart' emoji which leads to visual overlap ― how do you even account for that?!
[0] https://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/ https://journal.stuffwithstuff.com/2015/09/08/the-hardest-pr...