microsoft / microsoft/terminal
Strange behavior with ENABLE_VIRTUAL_TERMINAL_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
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 cccand press backspace a couple times. - Type
aaa bbb cccand 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied C# repro and run it in both CMD and PowerShell Core, testing the listed console input modes and key combinations. Compare the backspace behavior and post-exit arrow-key behavior, then determine whether either issue is owned by the console host or by Windows Terminal; no source files or tests are named in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100