vezel-dev / cathode

A terminal-centric replacement for the .NET console APIs.
https://docs.vezel.dev/cathode
BSD Zero Clause License
91 stars 7 forks source link

Support cooked input cancellation on Windows #63

Open alexrp opened 2 years ago

alexrp commented 2 years ago

See discussion on #46 and #61, as well as commit adf2a455ea0dbc35f48d3204179324a7e37c0d82.

alexrp commented 2 years ago

Started a discussion: microsoft/terminal#12143

alexrp commented 8 months ago

Proposed a whacky but potentially workable(?) hack for this here: https://github.com/microsoft/terminal/issues/12143#issuecomment-1873533831

Thoughts on that approach very welcome. (cc @scottbilas @xoofx)

scottbilas commented 8 months ago

I'm always in favor of an approach that works, even with caveats, over endless waiting for the gears to turn in a big software company. :) Seems like it's hard to get their attention on this.

alexrp commented 8 months ago

One aspect to consider is how this would work when standard I/O handles are redirected. Obviously, if we close redirected handles, we can't just simply reopen them again like we can with the console. We would need to special-case files, pipes, etc.

🤔

Looking at the .NET BCL, there's a whole bunch of code to handle cancellation in the FileStream backend code, both for the synchronous and asynchronous cases. So I'm now thinking this should be tied into #76 so we can make use of all the infrastructure that the .NET BCL already has in place for handling synchronous/asynchronous cancellation for those cases. Due to the Unix issue mentioned there, we could just do this work in the Windows terminal driver only, for now. (That's fine anyway, as the Unix terminal driver is quite clean in general, and UnixCancellationPipe has served us pretty well.)

alexrp commented 8 months ago

Sigh. Doesn't seem like that hack will work either.

I guess this might have worked on Windows 7, but Windows 8.1 completely changed how console handles work, so I figure that's why I had no luck here.

Sadness all around.

alexrp commented 8 months ago

Need to see if NtClose() will work, since CloseHandle() (apparently?) special-cases console handles.

alexrp commented 8 months ago

Ok, good news: It seems to work. (See the discussion on https://github.com/microsoft/terminal/issues/12143 for context.)

If you can, please either clone the Git repo and try the cancellation sample, or consume the GitHub packages and see if it works that way. If there are no issues with it, I'll make a release soon-ish.

alexrp commented 8 months ago

Going to reopen because of this: https://github.com/microsoft/terminal/issues/12143#issuecomment-1895629003

Still, we support cancellation of raw input now, so that's a lot better than nothing. This issue will track cancellation support for cooked input now.