microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
94.72k stars 8.19k forks source link

Code Points with 0 width occupies one column #12373

Closed eiximenis closed 2 years ago

eiximenis commented 2 years ago

Windows Terminal version

1.11.3471.0

Windows build number

10.0.19043.1466

Other Software

No response

Steps to reproduce

Running following NET6 code in Windows Terminal:

using System.Globalization;
using System.Text;

var s = "\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d\udc67*";
var graphemes = StringInfo.GetTextElementEnumerator(s);
while (graphemes.MoveNext()) {
    Console.WriteLine("Grapheme:" + graphemes.Current);
    var runes = graphemes.Current.ToString().EnumerateRunes();
    foreach (var rune in runes) {
        Console.WriteLine($"\tRune [{rune}] is {rune.Value} (0x{rune.Value:x}) - {string.Join('\0', rune.ToString().Select(c => $"\\u{(int)c:x}"))}");
    }
}

Console.WriteLine("123456789|123456789|123456789|123456789|123456789|123456789|");
Console.WriteLine(s);

Expected Behavior

This code creates a string named s with one grapheme cluster (๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง and one asterisk). Iterates over both graphemes, printing its code points individually. When the code point U+200d is printed it occupies one column even thought is a 0-width code point. That has the consequence that the grapheme is 11 columns wide (4 2+3) instead of 8 columns wide (4 2). Here is a screenshot of the program running in WT: image As you can see, the * starts in column 12, and the individual U+200d printed have one column width.

Default Ubuntu terminal seems to handle this a little bit better: although the grapheme cluster is not shown as a single character but a sequence of its individual code points, the U+200d does not have any width, and the overall width of the grapheme is 8: image As you can see, the * starts in column 9 and the U+200d does not have any width

Actual Behavior

Zero width code points seems to occupy one column

j4james commented 2 years ago

I believe this is a known limitation of the current buffer implementation. I think it's probably covered by issue #1472, or more broadly #8000.

zadjii-msft commented 2 years ago

Yeah, I'd reckon those are the same thing. Thanks!

/dup #1472 /dup #8000

ghost commented 2 years ago

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!