3 ms·
This stuff is a nightmare if you're trying to write a nice-looking terminal application. AFAICT there is no reliable way to determine how many cells an arbitrar
by breadbox 11y ago
This stuff is a nightmare if you're trying to write a nice-looking terminal application. AFAICT there is no reliable way to determine how many cells an arbitrary Unicode glyph will occupy when output to a terminal. None. You can use various wcwidth() functions as a first approximation, but you have to give up on things working in the general case, because there's no guarantee (in theory or in practice) that the terminal's font will actually honor the width defined by the standards. Hopefully this situation will slowly improve with the years, but given the level of neglect the terminal environment gets from standardization processes these days, I'm not entirely optimistic.
- mark-r 11y agoYou could always place each glyph individually, but that's likely to have subtle bugs too, while not being very performant.
- breadbox 11y agoI have used such a solution at times. But then you usually have the problem of overwriting half of a wide character, which is worse.
- jquast 11y agoThere is a method, using the report cursor position query to determine the current location of the cursor, you can then print question characters and re-read the loctation, the difference determining how many cells a character forwards the carriage.