Skip to content

GetContent() width does not match what is rendered for emoji flags #793

@karlc1

Description

@karlc1

For some emojis (at least flags), the width reported from tcell.GetContent() does not match what is shown on screen. The flags takes up 2 horizontal cells on screen, but the width returned is always 1.
I did some testing and found that mattn/go-runewidth also reports these as having width 1, however rivo/uniseg does correctly report the width of these flags as 2 if converted to a grapheme cluster.

Below is a short program demonstrating this:

package main

import (
	"fmt"
	tcell "github.com/gdamore/tcell/v2"
	"time"
)

func main() {

	screen, err := tcell.NewScreen()
	defer screen.Fini()
	if err != nil {
		panic(err)
	}
	if err = screen.Init(); err != nil {
		panic(err)
	}

	// sets character 🇩🇪
	screen.SetContent(1, 0, rune(127465), []rune{rune(127466)}, tcell.StyleDefault)
	_, _, _, width := screen.GetContent(1, 0)
	fmt.Printf("width of 🇩🇪: %v\n", width)

	// sets character 🏳️‍🌈
	screen.SetContent(2, 0, rune(127987), []rune{rune(65039), rune(8205), rune(127752)}, tcell.StyleDefault)
	_, _, _, width = screen.GetContent(2, 0)
	fmt.Printf("width of 🏳️‍🌈: %v\n", width)

	screen.Show()
	time.Sleep(time.Second * 5)
}

The screen shows the two flags spanning 2 columns each in both ghostty and kitty on my mac m2, but the printed output is:

width of 🇩🇪: 1
width of 🏳️‍🌈: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions