Pasting ๐คฆ๐ผโโ๏ธcharacter into repl throws exception and exits repl
Version
0.6.5
What happened?
I tried pasting the ๐คฆ๐ผโโ๏ธcharacter into the repl and it throws an exception:
> Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
at PrettyPrompt.Rendering.Screen.PositionCursor(Screen screen, ConsoleCoordinate cursor)
at PrettyPrompt.Rendering.Screen..ctor(Int32 width, Int32 height, ConsoleCoordinate cursor, ScreenArea[] screenAreas) โ
at PrettyPrompt.Renderer.<RenderOutput>g__Redraw|7_0(<>c__DisplayClass7_0&)
at PrettyPrompt.Renderer.RenderOutput(PromptResult result, CodePane codePane, OverloadPane overloadPane, CompletionPane completionPane, IReadOnlyCollection`1 highlights, KeyPress key)โ AppContext โ
at PrettyPrompt.Prompt.RenderSyntaxHighlightedOutput(Renderer renderer, CodePane codePane, OverloadPane overloadPane, CompletionPane completionPane, KeyPress key, String inputText, PromptResult result)โโโโโโโโโโ
at PrettyPrompt.Prompt.ReadLineAsync()
at CSharpRepl.ReadEvalPrintLoop.RunAsync(Configuration config) in D:\a\CSharpRepl\CSharpRepl\CSharpRepl\ReadEvalPrintLoop.cs:line 49
at CSharpRepl.Program.Main(String[] args) in D:\a\CSharpRepl\CSharpRepl\CSharpRepl\Program.cs:line 68
at CSharpRepl.Program.Main(String[] args) in D:\a\CSharpRepl\CSharpRepl\CSharpRepl\Program.cs:line 74
at CSharpRepl.Program.<Main>(String[] args)
Thanks for reporting this! It was definitely working before, and I thought we even had good integration tests around this. I'll see what happened.
Just a note for myself, ๐คฆ๐ผโโ๏ธ is composed of the following codepoints:
| Render | Codepoint | Name |
|---|---|---|
| ๐คฆ | U+1F926 | FACE PALM |
| ๐ผ | U+1F3FC | EMOJI MODIFIER FITZPATRICK TYPE-3 |
| โ | U+200D | ZERO WIDTH JOINER |
| โ | U+2642 | MALE SIGN |
| U+FE0F | VARIATION SELECTOR-16 |
I'm transferring this to the PrettyPrompt underlying library repository where it should be fixed.
- โ ๏ธ (U+26A0 U+FE0F) โ No crash
- ๐คฆ (U+1F926) โ No crash
- ๐คฆ๐ผ (U+1F926 U+1F3FC) โ CRASH
- ๐คฆโโ (U+1F926 U+200D U+2642) โ CRASH
- ๐คฆ๏ธ๏ธ (U+1F926 U+FE0F) โ No crash
- ๐ ฎ (U+20B9F; means "scold") โ No crash
- ็ฆฐ (U+79B0) โ No crash
- ็ฆฐ๓ (U+79B0 U+E0100; used in the name of the sister of the main character of Daemon Slayer: Kimetsu no Yaiba) โ CRASH
- ไพฎ๏ธ (U+4FAE U+FE00) โ No crash
- ๐ฉโ๐ป (U+1F469 U+200D U+1F4BB) โ No crash but not joinned
https://github.com/waf/PrettyPrompt/blob/4245c197b21500a634d9fbe29cad0e9d5f4753cc/src/PrettyPrompt/Rendering/Screen.cs#L100
This assertion fails.
https://github.com/waf/PrettyPrompt/blob/4245c197b21500a634d9fbe29cad0e9d5f4753cc/src/PrettyPrompt/Rendering/UnicodeWidth.cs#L244
This returns more than two and the returned value is set to .ElementWidth.
UnicodeWidth does not consider ๐ก๐ข๐ฃ or ๐๐, which are in the SMP (not BMP) and whose width should be treated as 1.
No Rune available only in .NET is used there. We can use StringInfo.GetTextElementEnumerator to split string into grapheme clusters now.