Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using emoji #3670

Closed
ChristopheI opened this issue Aug 19, 2024 · 5 comments
Closed

Using emoji #3670

ChristopheI opened this issue Aug 19, 2024 · 5 comments

Comments

@ChristopheI
Copy link

I'm trying this great repository (v 2.0.0-v2-develop.2169) but I can't managed emoji display ...

I previously checked "Unicode" scenario and even in this one I can't display this emoji: 👨

I tried with a little sample - cf. below
I'm using Windows and Visual Studio Enterprise.

In the TestWindow, the emoji is not well displayed.
Just after, using Console.WriteLine(), it's well displayed.

I guess I missed something but I don't know what.

Thank in advance

Code used:

internal class TestWindow: Window
{
    public TestWindow()
    {
        var str = char.ConvertFromUtf32(0x0001f4fa); // => 👨

        Label lbl1 = new()
        {
            X = 1,
            Y = 1,
            Text = str,
            Width = Dim.Fill()
        };

        Add(lbl1);

        Height = Dim.Fill();
        Width = Dim.Fill();
    }
}

Console.OutputEncoding = Encoding.Default;
Application.Run<TestWindow>().Dispose(); // <= Here the Emoji is not well displayed

var str = char.ConvertFromUtf32(0x0001f4fa); // => 👨
Console.WriteLine(str); // <= Here the Emoji is well displayed

@tig
Copy link
Collaborator

tig commented Aug 19, 2024

Emoji's are not fully supported yet.

They are not supported using WindowsDriver at all.

They are not supported using CursesDriver at all.

They partially work with NetDriver.

Use the CharacterMap scenario, and choose the Emojis Symbols range to see.

Closing as a dupe of the above issues.

@tig tig closed this as completed Aug 19, 2024
@ChristopheI
Copy link
Author

I miss this scenario.

Thank you for your quick answer, you save my day !

@dodexahedron
Copy link
Collaborator

dodexahedron commented Aug 19, 2024

Also good to note that unicode sequences in-line in strings in C# are legal by this syntax, rather than having to call that converter method:

string sillyString = "This strings ends with \U0001f4fa";

The case of the U is significant, as it dictates whether it interprets the following two or four bytes. Case of the hex doesn't matter.

Capital U considers the next 8 following hex digits as one UTF-32 codepoint (and there must be all 8 digits, with any leading zeros included). \U0001F468 -> 👨

Lower-case u considers the next 4 following hex digits ONLY, even if there are 8 digits. As with capital, all 4 must be present.
It interprets them as a UTF-16 codepoint, which can be the high surrogate in a surrogate pair, as that emoji would require. If you use this for surrogates, you specify both in sequence, high surrogate first: "\ud83d\udc68" -> 👨

Invalid code points are immediately known to the compiler as invalid and will be compile errors, which is a major advantage to doing them in-line.

Examples (note: if your console font does not have the required characters, you will see one ? per UTF-16 char (so ?? for UTF-32 or UTF-16 surrogate pairs):

Console.WriteLine ("This line ends with the letter 'a': \u0061");
Console.WriteLine ("This line ends with the string 'e0061': \u00650061");
Console.WriteLine ("This line ends with the letter 'a': \U00000061");
//Console.WriteLine ("This line is a compiler error (invalid codepoint): \U00610065");
Console.WriteLine ("This line ends with the emoji '\ud83d\udc68': \ud83d\udc68");
Console.WriteLine ("This line ends with the emoji '\ud83d\udc68': \U0001F468");

UTF-8 is a little more cumbersome, still:

Console.WriteLine (Encoding.UTF8.GetString("This line ends with the '@' symbol: \x40"u8));

@ChristopheI
Copy link
Author

Thank you for this explanation

@dodexahedron
Copy link
Collaborator

Sure thing!

I learned the specifics of the 4-byte case fairly recently, myself, so it was fresh in memory. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants