crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.29k stars 280 forks source link

Fixed Windows Terminal UTF-16 surrogate pair issue #857

Open kazatsuyu opened 10 months ago

kazatsuyu commented 10 months ago

Resolve #848

Windows Terminal seems to send the characters represented by surrogate pairs in the following order:

  1. key down event for the upper surrogate
  2. key up event for the upper surrogate
  3. key down event for the lower surrogate
  4. key up event for the lower surrogate

On the other hand, crossterm's surrogate pair handling does not distinguish between key-down/key-up events. This may be reasonable, as there are cases where another terminal sends only key-up events, but this results in an incorrect sequence of input from the Windows Terminal.

This fix uses only the last input in the case of a sequence of upper surrogates and ignores the input of lower surrogates with no upper surrogates; in the Windows Terminal, inputs 1 and 4 above are ignored and a single surrogate pair is created from inputs 2 and 3.

tasogare3710 commented 3 months ago

I am going to delete my fork, so read this(https://github.com/crossterm-rs/crossterm/issues/787). This issue related how to deal with the issue of an illegal bytes into the input. I may not be able to help because I don't have time to spend on crossterm.

https://github.com/tasogare3710/crossterm/tree/fix_handling_of_surrogate_pairs https://github.com/tasogare3710/crossterm/tree/illegal_surrogate_pairs_ppyp

joshka commented 3 months ago

I am going to delete my fork, so read this(#787). This issue related how to deal with the issue of an illegal bytes into the input. I may not be able to help because I don't have time to spend on crossterm.

https://github.com/tasogare3710/crossterm/tree/fix_handling_of_surrogate_pairs https://github.com/tasogare3710/crossterm/tree/illegal_surrogate_pairs_ppyp

I've pushed a backup copy of your branch to https://github.com/joshka/crossterm/tree/illegal_surrogate_pairs_ppyp (this branch contains both commits), and I'll keep it around, so you should be fine to delete your fork whenever you want. Thanks for the heads up.