crossterm icon indicating copy to clipboard operation
crossterm copied to clipboard

Surrogate pairs are ignored on Windows Terminal

Open kazatsuyu opened this issue 1 year ago • 1 comments

Describe the bug

On Windows Terminal, characters represented by UTF-16 surrogate pairs are not decoded properly and are ignored.

To Reproduce

  1. Run the code https://gist.github.com/kazatsuyu/d112afeebac0490efac267bbf2355f84 on Windows terminal.
  2. Copy and paste "abc🐈def".
  3. Confirm that the 🐈 is not displayed.

Expected behavior

The 🐈 is displayed.

OS

Windows 11 22621.2428

Terminal/Console

Windows Terminal

kazatsuyu avatar Dec 07 '23 17:12 kazatsuyu

I made a small modification to crossterm_winapi to allow it to display low-level input events. Windows Terminal seems to send two input events for surrogate pairs, one with key_down: true and one with key_down: false. image

When input from the console displayed by AllocConsole, only the one with key_down: false is sent. image

If one of consecutive upper surrogates and the lower surrogate in the absence of an upper surrogate were ignored, it would be possible to handle this kind of input pattern.

kazatsuyu avatar Dec 07 '23 17:12 kazatsuyu