Description
Environment
Windows build number: Microsoft Windows [Version 10.0.19041.153]
PowerShell Core 7.0.0
.NET Core 3.1.200
Steps to reproduce
C# program:
using System;
using System.Diagnostics;
using System.Text;
using static Vanara.PInvoke.Kernel32;
namespace Test
{
static class Program
{
static void Main()
{
var stdin = GetStdHandle(StdHandleType.STD_INPUT_HANDLE);
Debug.Assert(GetConsoleMode(stdin, out CONSOLE_INPUT_MODE inMode));
inMode |= CONSOLE_INPUT_MODE.ENABLE_VIRTUAL_TERMINAL_INPUT;
Debug.Assert(SetConsoleMode(stdin, inMode));
Console.WriteLine(Console.ReadLine());
}
}
}
(Uses the Vanara.PInvoke.Kernel32
NuGet package for convenience.)
You will need to test this program in both CMD and PowerShell Core.
Try doing these:
- Type
aaa bbb ccc
and press backspace a couple times. - Type
aaa bbb ccc
and press control + backspace several times.
Also, try using special keys (such as arrow keys) after the program closes.
Actual behavior
For the first part:
- Words are deleted with each backspace press.
- Characters are deleted with each control + backspace press.
This behavior happens in both CMD and PowerShell Core.
For the second part:
After closing the program, you'll notice that e.g. using the arrow keys echoes VT sequences (such as ^[[D^[[A^[[C
for left, up, right) rather than doing what they're supposed to. This behavior persists even if the ReadLine
+ WriteLine
is removed from the program.
This behavior only happens in CMD. PowerShell Core seems fine.
Expected behavior
I have no idea to what extent, if any, this behavior is actually buggy/unintended. But here is what I would expect as a user:
- Backspace and control + backspace behavior should not be swapped like this. This seems very strange and unlike other terminals.
- Console modes set from within a program should not persist after that program exits. PowerShell Core appears to get this right, while CMD does not, for whatever reason.
Perhaps worth noting that running CMD and PowerShell Core under Windows Terminal has no impact on the behavior seen here.
Also, I wasn't sure whether to file this as two separate issues. I can do that if necessary.