Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Better handling of wide glyphs (ask the terminal, not wcwidth)

I am working on a patch for rxvt-unicode, which basically asks the (Xft) font about the glyph's width, instead of using wcwidth(3).
This works around the issue that wcwidth is not updated for Unicode 9 on Linux yet, and is really required after all, since there is a private use area, and it depends on the font you are using for those glyphs (e.g. FontAwesome).

This method gets provided as a shared object then, which allows to LD_PRELOAD it (overwriting wcwidth and wcswidth).
In this case Zsh will use the same method, and everything is fine!

But this shows that there is a problem between Zsh and the terminal, since the display gets out of sync, i.e.

1. I insert "🐍", it gets two cells in the terminal:
% 🐍
2. I add "a" after it.  "🐍a" gets displayed (3 cells), but the offset gets shifted to the right:
%  🐍a
This happens also already when only moving the cursor to the left after inserting the snake glyph.
So I wondered if Zsh could be smarter even without the custom wcwidth(3) in LD_PRELOAD: there is CSI 6 n ('\e[6n'), which can be used to ask the terminal about the current position.
This could be used for a certain range of characters, where zle (?) would query the position before and after displaying it to get the "real" width (as seen by the terminal).

What do you think?

While looking into the source regarding this, I've found that there is a useful function already to get some info ("whatcursorposition", bound to "ga" in Vim mode).
Regardless of the idea above, I think it makes sense to include info from "CSI 6 n" there.

I assume there are methods already that query the terminal through ANSI control codes?
I've found Functions/Misc/promptnl, but that uses shell code.


Attachment: signature.asc
Description: OpenPGP digital signature

Messages sorted by: Reverse Date, Date, Thread, Author