Programmatically tell if a Unicode character takes up more than one character space in a terminal

后端 未结 3 782
失恋的感觉
失恋的感觉 2020-12-10 05:03

I discovered that in the Mac OS X Terminal, some Unicode characters take up more than one character space. For example 27FC (long rightwards arrow from bar). It prints two

3条回答
  •  天涯浪人
    2020-12-10 05:28

    No, since there's no way to tell what font the terminal is using. Always use a monospace font, lesson learned.

    It happens because the terminal is using a "cell" font layout engine (i.e. characters are printed at specific X and Y coordinates regardless of their actual size) whereas the browser is using a "flow" font layout engine (subsequent characters print where the previous character ended).

提交回复
热议问题