From 86147f14ef3003e51f7c21b541007521d167b46a Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 5 Sep 2018 18:42:39 -0400 Subject: [PATCH] fixes #233 Want zero-width joiners support --- _demos/unicode.go | 19 +++++++++++++++++++ cell.go | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/_demos/unicode.go b/_demos/unicode.go index a7831df..ee046fb 100644 --- a/_demos/unicode.go +++ b/_demos/unicode.go @@ -38,7 +38,22 @@ func puts(s tcell.Screen, style tcell.Style, x, y int, str string) { i := 0 var deferred []rune dwidth := 0 + zwj := false for _, r := range str { + if r == '\u200d' { + if len(deferred) == 0 { + deferred = append(deferred, ' ') + dwidth = 1 + } + deferred = append(deferred, r) + zwj = true + continue + } + if zwj { + deferred = append(deferred, r) + zwj = false + continue + } switch runewidth.RuneWidth(r) { case 0: if len(deferred) == 0 { @@ -109,6 +124,10 @@ func main() { putln(s, "Airplane: \u2708 (fly away)") putln(s, "Command: \u2318 (mac clover key)") putln(s, "Enclose: !\u20e3 (should be enclosed exclamation)") + putln(s, "ZWJ: \U0001f9db\u200d\u2640 (female vampire)") + putln(s, "ZWJ: \U0001f9db\u200d\u2642 (male vampire)") + putln(s, "Family: \U0001f469\u200d\U0001f467\u200d\U0001f467 (woman girl girl)\n") + putln(s, "") putln(s, "Box:") putln(s, string([]rune{ diff --git a/cell.go b/cell.go index 496f10f..b743446 100644 --- a/cell.go +++ b/cell.go @@ -52,6 +52,10 @@ func (cb *CellBuffer) SetContent(x int, y int, i := 0 for i < len(c.currComb) { r := c.currComb[i] + if r == '\u200d' { + i += 2 + continue + } if runewidth.RuneWidth(r) != 0 { // not a combining character, yank it c.currComb = append(c.currComb[:i-1], c.currComb[i+1:]...)