You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Some Devanagari including Viramas return wrong width #1
Hi! Great stuff. Tim aka Rockorager pointed out uucode in a conversation. I am currently playing with zg.
क्ष - This indic scripture is rendered as two cells by all terminals I tested (ghostty, kitty, alacritty, vscode),
but both zg and uucode give me width 1, which makes my rendering end up with ghost cells.
Any idea why this particular one (there might be otheres) returns 1 but is rendered as 2 by terminals?
What's going on is that wcwidth gives only the "width" of a code point, but the actual resulting width of the grapheme (in this case all 4 code points) is likely to be more complicated. Note that the U+200D there is the zero width joiner, and in fact it looks like this string is on that wikipedia page.
The wcwidth is part of the built-in extensions, that I've nested under src/x and required using the advanced configuration to pull in, but initially I even wanted this to be in a separate uucode.x repo/library, but the zig build integration got too complicated (and there's a bug to figure out).
The reason this is an extension is that it's not part of the Unicode standard. See the source code at wcwidth.zig to see where I'm basing it from.
which makes my rendering end up with ghost cells.
Back to your issue, though, for your use case, are you computing grapheme clusters before continuing any rendering? If so, you might be able to add up the wcwidth for each code point and that might get you a better value? I'm not actually sure how terminals such as Ghostty are handling this, but I am curious to look at some point.
Like I mentioned, this is all outside of the Unicode standard, sadly.
I'll leave this open for now, as I'm still getting up to speed on terminal use cases, and if I add some equivalent to strWidth (as an extension), then I'd like to have a better idea of what's standard there.
Thanks for looking into this! I wasn't aware that was out of standard. Maybe worth looking into what Ghostty does internally to end up with 2 cells for it. They have an esoteric c++ implementation they use currently, couldn't figure it out, that's how Tim ended up pointing me here.
Most things work for now switching between unicode and wcwidth like libvaxis does, so that's okay. Would love to get to the bottom of this at some point though.
I'd definitely love to get to the bottom of this, and also fully understand what Ghostty is doing here. I'll circle back to this eventually.
In the meantime, I was thinking of adding this:
var it = uucode.grapheme.Iterator.initUtf8(text); // tentative API, still an open issue: https://github.com/jacobsandlund/uucode/issues/5
var g = it.next()
uucode.x.grapheme.unverifiedWcwidth(g); // hopefully 2 for `क्ष`
For now that grapheme.unverifiedWcwidth(g) method would:
take the width of the first non-zero-width code point (as per ziglyph and zg),
but, if there's a ZWJ (U+200D), then make that a width of 2
the use of ZWJ in some of these scripts pretty much means combining two or more glyphs into one, so that's probably safer to assume that it's going to be wide.
I'd like to get a better idea of what to do here, but maybe that will be useful enough to do for now?
Hey @kommander, I just added a grapheme.Iterator and then a x.grapheme.unverifiedWcwidth in 577f0d0. I hope that works decently well if you give that a try!
I'll leave this issue open until I've gotten a chance to take a deeper look, and see if this algorithm is the most reasonable thing to do (given it's non-standard), or if Ghostty does something better.
Separately, sometime when I get a chance, I'm going to try and help some of the uucode users update to some of the latest changes (e.g. libvaxis and opentui)!
Activity
jacobsandlund commentedon Aug 31, 2025
Hi @kommander, glad you got pointed here! Issue #1, woohoo! Turns out I didn't have notifications configured properly (now I do).
I took a look at that string with this:
and that gives me:
What's going on is that
wcwidthgives only the "width" of a code point, but the actual resulting width of the grapheme (in this case all 4 code points) is likely to be more complicated. Note that the U+200D there is the zero width joiner, and in fact it looks like this string is on that wikipedia page.The
wcwidthis part of the built-in extensions, that I've nested undersrc/xand required using the advanced configuration to pull in, but initially I even wanted this to be in a separate uucode.x repo/library, but the zig build integration got too complicated (and there's a bug to figure out).The reason this is an extension is that it's not part of the Unicode standard. See the source code at wcwidth.zig to see where I'm basing it from.
Back to your issue, though, for your use case, are you computing grapheme clusters before continuing any rendering? If so, you might be able to add up the
wcwidthfor each code point and that might get you a better value? I'm not actually sure how terminals such as Ghostty are handling this, but I am curious to look at some point.jacobsandlund commentedon Sep 1, 2025
Oh @kommander I see, you're using Tim's code here: https://github.com/sst/opentui/pull/90/files#diff-957e7436e16569e080cb465f4caebbbd00fa2710550b7e790f1874fd62010033, and that's using
zgstrWidth. Looks like that says// Only adding width of first non-zero-width code point.in the zg source, so indeed that'll still return 1 instead of adding the 1 + 1. It looks likeziglyphis doing the same thing in itsstrWidth. I know Ghostty doesn't usestrWidth, so it might be combining the code point widths into a wide grapheme some other way, and I haven't gotten to the bottom of it, yet.Like I mentioned, this is all outside of the Unicode standard, sadly.
I'll leave this open for now, as I'm still getting up to speed on terminal use cases, and if I add some equivalent to
strWidth(as an extension), then I'd like to have a better idea of what's standard there.kommander commentedon Sep 3, 2025
Thanks for looking into this! I wasn't aware that was out of standard. Maybe worth looking into what Ghostty does internally to end up with 2 cells for it. They have an esoteric c++ implementation they use currently, couldn't figure it out, that's how Tim ended up pointing me here.
Most things work for now switching between unicode and wcwidth like libvaxis does, so that's okay. Would love to get to the bottom of this at some point though.
jacobsandlund commentedon Sep 3, 2025
I'd definitely love to get to the bottom of this, and also fully understand what Ghostty is doing here. I'll circle back to this eventually.
In the meantime, I was thinking of adding this:
For now that
grapheme.unverifiedWcwidth(g)method would:I'd like to get a better idea of what to do here, but maybe that will be useful enough to do for now?
kommander commentedon Sep 10, 2025
Sorry for my late answers, I don't get github notifications.
That could very much help! I hope Tim can give some insights into Ghostty.
jacobsandlund commentedon Sep 11, 2025
sweet, i'll make sure to have at least something for this in by a 0.1.0 release or shortly after
jacobsandlund commentedon Sep 16, 2025
Hey @kommander, I just added a
grapheme.Iteratorand then ax.grapheme.unverifiedWcwidthin 577f0d0. I hope that works decently well if you give that a try!I'll leave this issue open until I've gotten a chance to take a deeper look, and see if this algorithm is the most reasonable thing to do (given it's non-standard), or if Ghostty does something better.
jacobsandlund commentedon Sep 24, 2025
Once I get to this, this looks like a good resource: https://www.jeffquast.com/post/ucs-detect-test-results/
kommander commentedon Oct 5, 2025
I am working on text rendering again and will give this a go in the coming week.
terminal: change cell width when wider grapheme detected (#10465)
jacobsandlund commentedon Mar 19, 2026
Hey @kommander I'm finally going to close this issue. It's been fixed in
uucodefor a while, but I kept it open because I wanted to see how Ghostty handled this. Well, it was "working" before in Ghostty because Ghostty had an out-of-date "grapheme break" algorithm, so क्ष was treated as two characters and thus took 2 cells. I've since made a number of PRs to Ghostty, and Ghostty 1.3 now correctly treats this as a single character, of width 2, and it usesuucodeto determine that width! See https://ghostty.org/docs/install/release-notes/1-3-0#unicode-and-international-text-renderingSeparately, sometime when I get a chance, I'm going to try and help some of the
uucodeusers update to some of the latest changes (e.g.libvaxisandopentui)!