zsh-workers
 help / color / mirror / code / Atom feed
* Better handling of wide glyphs (ask the terminal, not wcwidth)
@ 2016-11-05 22:04 Daniel Hahler
  2016-11-05 22:37 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Hahler @ 2016-11-05 22:04 UTC (permalink / raw)
  To: Zsh Hackers' List


[-- Attachment #1.1: Type: text/plain, Size: 1764 bytes --]

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.


Cheers,
Daniel.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 163 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-11-07  2:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-05 22:04 Better handling of wide glyphs (ask the terminal, not wcwidth) Daniel Hahler
2016-11-05 22:37 ` Bart Schaefer
2016-11-07  1:09   ` Daniel Hahler
2016-11-07  2:54     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).