Measures a string one visible character at a time
All 12 scenarios hold
The formatter measures alignment in terminal display columns, not in characters. These rules say how wide a value renders in a monospaced font. The Column width feature and the Cell padding and alignment feature build on them.
A string is as wide as the characters a reader sees in it. A visible character can be several code points: a letter and its accent, a flag, emoji joined into one picture, an emoji with a skin tone, a symbol followed by the emoji selector, a Hangul syllable written as its letters. Each such character takes the columns of the widest kind it holds, once, so a joined emoji takes two columns, as a terminal draws it.
A null string and an empty string both draw nothing. The formatter measures both as zero, and rejects neither.
| Scenario | Text | Width? |
|---|---|---|
| Every glyph one column | Hello | 5 |
| Every glyph two columns | 你好世界 | 8 |
| One-column and two-column mixed | Hello 👋 World | 14 |
| A letter and a combining accent | é | 1 |
| A symbol with the emoji selector | ☀️ | 2 |
| A flag | 🇳🇴 | 2 |
| Emoji joined into one picture | 👨👩👧 | 2 |
| An emoji with a skin tone | 👍🏽 | 2 |
| A keycap | 1️⃣ | 2 |
| A Hangul syllable written as letters | 한 | 2 |
| A null string | 0 | |
| An empty string | “” | 0 |