microsoft/Terminal

Strange behavior with ENABLE_VIRTUAL_TERMINAL_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT

Open

#4,949 创建于 2020年3月16日

在 GitHub 查看
 (23 评论) (1 反应) (0 负责人)C++ (3,212 fork)batch import
Area-CookedReadArea-InputHelp WantedIssue-BugPriority-2Product-Conhost

仓库指标

Star
 (35,764 star)
PR 合并指标
 (平均合并 27天 19小时) (30 天内合并 24 个 PR)

描述

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:

  1. Type aaa bbb ccc and press backspace a couple times.
  2. 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:

  1. Words are deleted with each backspace press.
  2. 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.

贡献者指南