spectreconsole / wcwidth

A .NET library that calculates the width of Unicode characters.
MIT License
49 stars 13 forks source link

【Bug】Some special symbols cannot be processed #8

Closed sdwdjzhy closed 1 week ago

sdwdjzhy commented 2 weeks ago

Information

Describe the bug

Some special characters cannot be counted as 2, like ℃、℉

To Reproduce


using Spectre.Console;

var table = new Spectre.Console.Table();
table.AddColumns("Name", "Value", "Description");
table.AddRow("test", "中文", "中文 mix English");
table.AddRow("test", "中文", "使用特殊字符℃");
table.AddRow("test", "中文", "使用特殊字符℉");
table.AddRow("test", "中文", "使用特殊字符");

AnsiConsole.Write(table);

Expected behavior Table alignment

Screenshots

微信截图_20240827111457

Additional context Add any other context about the problem here.


Please upvote :+1: this issue if you are interested in it.

sdwdjzhy commented 2 weeks ago

This is not an urgent issue, I'll wait for Nuget to release it

I am wondering if I need to provide an event to correct the width, pass in the current character, return whether it has been processed, and customize the width


class Arg
{
    public bool Handle { get; set; }
    public int? Width { get; set; }
}

// the event like

void Fun(char c, Arg e)
{
    if(e.Handle) return;
    if (c == '℃')
    {
        e.handle = true;
        e.Width = 2;
    }

    // Other, handle by default
    // e.Handle = false;
    // e.Width = null;
}
patriksvensson commented 2 weeks ago

Moving this issue over to the wcwidth repository, since it's a bug there.

sdwdjzhy commented 1 week ago

i see the pull request will be automatically merged. Do you need to review it?

patriksvensson commented 1 week ago

@sdwdjzhy You haven't created a pull request for this issue, so not sure what will be merged.

patriksvensson commented 1 week ago

It looks like this has something to do with your terminal font, because and are not considered to be wide characters.

Maybe and aren't available in your terminal font, and the terminal falls back to another font with a different width?

I've tested this using 6 terminals on 3 different OSes and cannot reproduce what you're seeing.

image

image

image