Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delayed ReadLine after on enter with CMD (outside of Windows Terminal) #61

Closed
xoofx opened this issue Dec 30, 2021 · 5 comments
Closed
Labels
area: drivers Issues related to the terminal drivers. area: interaction Issues related to user interaction. os: windows Issues that are specific to Windows (10, 11, etc).
Milestone

Comments

@xoofx
Copy link

xoofx commented Dec 30, 2021

Followup of #9
While trying this program with CMD outside of Windows Terminal:

Terminal.OutLine("Type some text:");
while (true)
{
    var line = Terminal.ReadLine();
    if (line == null) break;
    Terminal.OutLine(line);
}

The input seems to not always work on ENTER, sometimes it happens straight, sometimes it happens after the first inputted line. It works fine from the Windows Terminal though.

  • OS: Windows 11
  • Terminal: 0.5.39
@alexrp
Copy link
Member

alexrp commented Dec 30, 2021

I can reproduce this (in the scrolling sample also).

@alexrp alexrp self-assigned this Dec 30, 2021
@alexrp alexrp added this to the v1.0 milestone Dec 30, 2021
@alexrp alexrp added area: drivers Issues related to the terminal drivers. area: interaction Issues related to user interaction. os: windows Issues that are specific to Windows (10, 11, etc). state: confirmed Bugs that have been confirmed and are reproducible. type: bug and removed type: bug labels Dec 30, 2021
@alexrp
Copy link
Member

alexrp commented Dec 30, 2021

This looks like a regression, actually. This used to work.

I suspect it's probably related to the whole ReadConsoleW workaround on Windows:

https://github.com/alexrp/system-terminal/blob/438cfb0311c25cf3bc75f0981b8bcaeb8cf7ab75/src/core/Terminals/Windows/WindowsTerminalReader.cs#L40-L156

@alexrp
Copy link
Member

alexrp commented Dec 30, 2021

Stepping through the code, ReadConsoleW is doing exactly what it should be doing: Returning the pressed characters followed by \r and \n. Nothing unusual there.

Given that this works fine in Windows Terminal, I suspect a console host bug...

@xoofx I don't suppose you have a Windows 10 machine available to test on?

@alexrp
Copy link
Member

alexrp commented Dec 30, 2021

OK, ignore all of the above; my original hunch in #9 (comment) was correct. WindowsCancellationEvent is the culprit. Removing the call to PollWithCancellation makes things work.

Now to figure out why WaitForMultipleObjects on the console input handle behaves differently between Windows Terminal and the Windows console host. Joy...

@alexrp
Copy link
Member

alexrp commented Dec 30, 2021

It appears that the console input buffer either contains slightly different input records than what we see with Windows Terminal, or that the console host processes them differently. Either way, the logic here is not working under the console host:

https://github.com/alexrp/system-terminal/blob/438cfb0311c25cf3bc75f0981b8bcaeb8cf7ab75/src/core/Terminals/Windows/WindowsTerminalReader.cs#L55-L86

At this point I'm likely to just rip cancellation support out of the Windows driver. The amount of hacks I'm having to pile here to make what should be a simple poll(2) call kinda-sorta work on Windows is getting out of hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: drivers Issues related to the terminal drivers. area: interaction Issues related to user interaction. os: windows Issues that are specific to Windows (10, 11, etc).
Development

No branches or pull requests

2 participants