cathode
cathode copied to clipboard
Support cooked input cancellation on Windows
See discussion on #46 and #61, as well as commit adf2a455ea0dbc35f48d3204179324a7e37c0d82.
Started a discussion: microsoft/terminal#12143
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)
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.
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.)
Sigh. Doesn't seem like that hack will work either.
- Reading from
GetStdHandle(STD_INPUT_HANDLE)
and then closing that handle from another thread doesn't cause the read to get interrupted for some reason. - Reading from
CreateFile("CONIN$", ...)
and then closing that handle from another thread just causesCloseHandle()
to block until the read completes.
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.
Need to see if NtClose()
will work, since CloseHandle()
(apparently?) special-cases console handles.
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.
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.