PowerShell / PSReadLine

A bash inspired readline implementation for PowerShell
BSD 2-Clause "Simplified" License
3.77k stars 298 forks source link

Cyrillic breaks CTRL+ combos #2865

Open 243083df opened 3 years ago

243083df commented 3 years ago

Environment

PS version: 7.1.4
PSReadline version: 2.1.0
os: 10.0.19041.1165 (WinBuild.160101.0800)
PS file version: 7.1.4.0
HostName: ConsoleHost
BufferWidth: 120
BufferHeight: 9001

Steps to reproduce

Open powershell 7.1.4 in windows terminal. In cyrillic keymap press CTRL+С (C cyrillic) CTRL not working and terminal show C CTRL+A and CTRL+C not working after it in both keymaps

There is also another cases but it hard to reproduce.

Expected behavior

Actual behavior

CTRL+C working correctly

243083df commented 3 years ago

https://github.com/microsoft/terminal/issues/11232

daxian-dbw commented 3 years ago

What keyboard layout are you using?

243083df commented 3 years ago

Russian (Russia) https://docs.microsoft.com/en-us/globalization/keyboards/kbdru

daxian-dbw commented 3 years ago

@iSazonov Are you able to reproduce this issue?

iSazonov commented 3 years ago

No. The same PSRL 2.1.0 but PS 7.2: image

daxian-dbw commented 3 years ago

Thank you @iSazonov! You were using the Russian Keyboard, right?

243083df commented 3 years ago

I come back with mysterious addition. When open PS and CTRL+C(Cyrillic), PS react like Cyrillic C entered. And when do CTRL+C just add c, and CTRL+Ф add 'ф', but if i switch layout to ENG, and input a then a will be added, but when i press CTRL+A then PS treat A as russian ф

iSazonov commented 3 years ago

Thank you @iSazonov! You were using the Russian Keyboard, right?

Yes, and I switched to Russian layout.

iSazonov commented 3 years ago

Windows Terminal versionI I tested with is latest Preview 1.11.2421.

daxian-dbw commented 3 years ago

@243083df Given that @iSazonov couldn't reproduce the issue using Russian Keyboard, we need more information on the repro steps. Can you be more specific on what keyboard you are using, what display language and default language, as well as what additional software you installed that you think may affect the language input on your machine?

243083df commented 3 years ago

I debugged this problem and found what user32.dll works only with one locale with that it started. https://github.com/PowerShell/PSReadLine/blob/master/PSReadLine/Keys.cs#L150 Since if you start PSReadline and press english CTRL+any then ToUnicode always return english chars in chars. And if you (re)start PSReadline and press cyrillic CTRL+any, ToUnicode always return cyrillic chars in chars.

user32.dll has version 10.0.19041.1202

243083df commented 3 years ago
Have this language settings ![image](https://user-images.githubusercontent.com/29660847/135147345-35b97651-89b8-4717-9808-66465b8f18ba.png)
This for english ![image](https://user-images.githubusercontent.com/29660847/135147397-3da16087-e3b8-4480-941c-bc7ca829b988.png)
This for russian ![image](https://user-images.githubusercontent.com/29660847/135147452-c857fa6d-7a7f-4276-8b86-3dc69cd65036.png)
243083df commented 3 years ago

Bug wont reproduce on ubuntu 20.04 LTS under WSL2. Same PC.

243083df commented 3 years ago

I am debug further and find out that https://github.com/PowerShell/PSReadLine/blob/master/PSReadLine/ReadLine.cs#L103 With ctrl return in KeyChar not ascii code, but alphabelic so CTRL+C become 3 '\u0003' and char.IsControl at https://github.com/PowerShell/PSReadLine/blob/master/PSReadLine/Keys.cs#L231 return true

Console.ReadKey(); return same result so seems thats it used to readkeys

ForNeVeR commented 3 years ago

This is a duplicate of https://github.com/PowerShell/PSReadLine/issues/1393. You may also take a look at my previous attempt at fixing this, PR https://github.com/PowerShell/PSReadLine/pull/1848.

For the record, this still 100% reproduces for me using PowerShell 7.2 and any Windows Terminal (or conhost for that matter), on all of my Windows 10 and Windows 11 computers.

o-sdn-o commented 2 weeks ago

Stable repro (PSReadLine 2.4.0-beta0): https://github.com/microsoft/terminal/issues/17197#issuecomment-2478641782