Comments (6)
Setting a flag and writing some garbage with ioctl(TIOCSTI)
could potentially be an option. The equivalent on Windows should simply be WriteConsole
on the input handle (probably, maybe). Or WriteConsoleInput
.
from cathode.
Setting a flag and writing some garbage with
ioctl(TIOCSTI)
could potentially be an option.
Then again, setting a flag and sending a signal should work just as well and seems less hacky. No such mechanism on Windows, though. Would also require knowing the thread ID of the reading thread.
from cathode.
Here's an approach I think is workable and way less hacky.
TerminalReader.Read
(and APIs that use it) should be changed to accept an optional CancellationToken
.
We will create a pipe on startup. Instead of trying to read
immediately, we will poll
on the input FD and pipe read FD. When poll
returns, we check if the pipe had data written. If yes, we drain it and throw an OperationCanceledException
(leaving any potential data in the input FD unread). If no, proceed to read input as normal.
The TerminalReader
will hook into the cancellation token with UnsafeRegister
. The callback will simply write a byte to the pipe write FD to indicate that cancellation is requested.
This scheme should in principle work the same on Windows - just replace pipe
with CreatePipe
, poll
with WaitForMultipleObjects
, read
with ReadConsole
/ReadFile
, etc.
from cathode.
Bad news: WaitForMultipleObjects
doesn't work on pipes. So the Unix approach won't translate neatly to Windows.
from cathode.
Mostly done in fe53706 (with a kinda gross but functional workaround for Windows).
Still need to see if cancellation can somehow be plumbed through for ReadLine
in addition to ReadRaw
.
from cathode.
Still need to see if cancellation can somehow be plumbed through for
ReadLine
in addition toReadRaw
.
It will probably be possible in .NET 7; see:
Closing this.
from cathode.
Related Issues (20)
- Get rid of remaining avoidable allocations in `ControlSequences`
- Support `OSC 9 ; 9` and `OSC 7` for reporting the working directory HOT 1
- Handle cancellation of `TextReader`/`TextWriter` access resiliently
- Use `System.Drawing.Size` and `System.Drawing.Color`
- Wrap `FlushAsync(CancellationToken)` in `SynchronizedTextWriter` (.NET 8)
- Upgrade to .NET 8
- Build samples separately from core libraries HOT 1
- Support for image/graphics control sequences
- Write the 2nd progress report HOT 1
- Review the list of terminal emulators we support
- `ChildProcessReader` can bubble up internal exceptions to `ChildProcess.Completion`
- `ChildProcess.Kill()` can let internal exceptions through
- Long term: Rewrite the native support library in Zig
- Move `UnixCancellationPipe` logic to the native library
- Support musl-based systems (e.g. Alpine) HOT 5
- Write the 3rd progress report HOT 1
- Writing to Terminal with \n inconsistent on Windows vs Linux and vs other libraries HOT 11
- Ability to use Arguments on ChildProcess rather than ArgumentList HOT 6
- Switch minimum TFM to `net9.0`
- Cancellation on ReadAsync causes next ReadAsync to skip a byte (raw mode) HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cathode.