gui-cs / Terminal.Gui

Cross Platform Terminal UI toolkit for .NET
MIT License
9.68k stars 690 forks source link

Non-BMP code points don't work on Linux #2615

Open tig opened 1 year ago

tig commented 1 year ago

Unicode issue related to: #2610

See also: https://github.com/gui-cs/Terminal.Gui/issues/2616

Try as I might, I can't seem to get the CursesDriver to output non-BMP code points.

NetDriver works well:

image

I've gone as far code like this:

                    if (rune.IsBmp) {
                        Contents [Row, Col, 0] = rune.Value;
                        Curses.addch (Contents [Row, Col, 0]);
                    } else {
                        var column = Col;
                        ReadOnlySpan<char> remainingInput = rune.ToString ().AsSpan ();
                        while (!remainingInput.IsEmpty) {
                            // Decode
                            OperationStatus opStatus = Rune.DecodeFromUtf16 (remainingInput, out Rune result, out int charsConsumed);

                            if (opStatus != OperationStatus.Done) {
                                result = Rune.ReplacementChar;
                            }
                            Contents [Row, column, 0] = result.Value;
                            Contents [Row, column, 1] = CurrentAttribute;

                            Curses.attrset (Contents [Row, column, 1]);
                            Curses.mvaddch (Row, column, Contents [Row, column, 0]);

                            // Slice and loop again
                            remainingInput = remainingInput.Slice (charsConsumed);
                            column++;
                        }
                        Curses.move (Row, Col);
                    }
                    Curses.attrset (curAttr);
                }

CursesDriver results in this:

image
BDisp commented 1 year ago

You are in the right way, good catch. I'm working on a new PR that get rid the NStack dependence that fix #92. What you are relating here for a long time I already realized the same.

tig commented 1 year ago

You are in the right way, good catch. I'm working on a new PR that get rid the NStack dependence that fix #92. What you are relating here for a long time I already realized the same.

Uh-ohl I started the same thing today. I've made huge progress, starting just with ConsoleDriver and subclasses.

I'll push my PR and you can see what I've done....