-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Steps to reproduce
- Use Windows PowerShell 7 and PowerShell 7 in WSL.
- Launch Windows Powershell in Windows Terminal
- Launch wsl,
pwsh - Exit Linux powershell
- Observe the arrow keys
Linux powershell emits the escape sequence DECSET DECCKM[1] on startup before it emits the first prompt.
This reconfigures the cursor keys, which usually emit CSI A...D, to emit SS3 A...D instead.
Linux powershell can handle SS3 arrow key sequences. This is fine.
When Linux powershell exits, it does not restore DECCKM to its original state. All applications that manipulate global terminal state are expected to return the terminal to "normal" once they are done.
Because the state is not restored when you exit Linux powershell, Windows powershell (which doesn't know that the terminal state has been changed) will start to receive SS3 arrow key sequences.
Windows powershell cannot handle SS3 arrow key sequences, and it ignores them, so the arrow keys do not work.
This also reproduces when you SSH to a linux machine, but WSL is easier for a self-contained repro.
Expected behavior
DECCKM is disabled on exit.
Actual behavior
DECCKM remains enabled on exit, downstream applications get confused.
Environment data
(dhowett-sl) ~ % $PSVersionTable
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
(dhowett-sl) ~ % wsl pwsh -c '\$PSVersionTable'
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Linux 4.19.84-microsoft-standard #1 SMP Wed Nov 13 11:44:37 UTC 2019
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
[1] Notes about DECCKM
CSI ? Pm h
DEC Private Mode Set (DECSET).
Ps = 1 ⇒ Application Cursor Keys (DECCKM), VT100.
DECCKM reconfigures the arrow keys as follows
Key Normal Application
-------------+----------+-------------
Cursor Up | CSI A | SS3 A
Cursor Down | CSI B | SS3 B
Cursor Right | CSI C | SS3 C
Cursor Left | CSI D | SS3 D
-------------+----------+-------------
[2] I've investigated PowerShell, PSReadline and dotnet/runtime, and I cannot determine where DECCKM is being enabled.