-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Background and motivation
Feature Ask
Today, when ENABLE_VIRTUAL_TERMINAL_INPUT is set to the input handler on Windows, Console.ReadKey will just pass through all the VT sequences emitted by the terminal. It would be great if a configuration is added to System.Console so that we can make Console.ReadKey parse VT sequences in this case similarly to how Console.ReadKey works on Unix platforms. Of course, this will be an opt-in functionality, maybe through a static property on System.Console, say Console.ForceParseVTSequence, which by default is false, so the existing behavior is unchanged.
Motivation
The right-clicking paste causes quite some long-standing problems in PowerShell (see PowerShell/PSReadLine#579 and #38966 for details), and we are seeking to solve it by leveraging the Bracketed Paste Mode, which Windows Terminal started to support earlier this year. To enable the bracketed paste support in Windows Terminal, the application needs to set the ENABLE_VIRTUAL_TERMINAL_INPUT mode to the console's input handler, however, that will cause Console.ReadKey to just pass through VT sequences on Windows, which would require the application itself to parse all the VT sequences.
We don't want to re-implement a VT sequence parser in PowerShell, especially given that .NET already has one that works on Unix platforms. I think it's reasonable to ask .NET to allow a similar behavior on Windows as an opt-in feature, which can benefit all applications that have the similar need.
Related Issues
#60101
PowerShell/PSReadLine#1471
API Proposal
Add a static property bool static ForceParseVTSequence to System.Console to turn on/off the feature.
Its default value is false, so that current behavior is unchanged by default.
API Usage
// Set 'ENABLE_VIRTUAL_TERMINAL_INPUT' mode to the console's input handler on Windows,
// then turn on this feature in C# code.
Console.ForceParseVTSequence = true;
// .NET will map the VT sequence emitted by the Windows Terminal to valid ConsoleKeyInfo values,
// similarly to how this behaves on Linux.
Console.ReadKey()Risks
.NET depends on the terminfo database to map VT sequences to specific key combinations on Unix platforms, but Windows doesn't have such terminfo database. I understand this would be problem to enable a VT parser on Windows.
Would it be possible to assume VT100 as the standard on Windows? According to the doc, Windows Terminal emits sequences based on VT100:
The behavior of the following sequences is based on the VT100 and derived terminal emulator technologies, most specifically the xterm terminal emulator. More information about terminal sequences can be found at http://vt100.net and at http://invisible-island.net/xterm/ctlseqs/ctlseqs.html.