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:]...)