Skip to content

ChannelTextReader

A TextReader backed by a Channel<T> that supports both char-level reads (ReadAsync(Memory<char>, CancellationToken)) and line-level reads (ReadLineAsync(CancellationToken)). Transport code pushes raw text via Enqueue(string); the reader handles internal buffering and newline parsing.

public sealed class ChannelTextReader : TextReader, IDisposable

Signals that no more input will arrive (EOF).

public void Complete()

Pushes a raw text chunk from the transport layer.

public void Enqueue(string text)
  • text (string): Text to enqueue.

ReadAsync(Memory<char>, CancellationToken)

Section titled “ReadAsync(Memory<char>, CancellationToken)”

Reads characters into buffer, returning the number of characters read. Returns 0 when the channel is completed and no buffered data remains. This method is used by VtProbe for char-level terminal detection.

public override ValueTask<int> ReadAsync(Memory<char> buffer, CancellationToken cancellationToken = default)

ValueTask<int>

Reads a complete line, accumulating across chunks until a line terminator is found. Returns null when the channel is completed and no buffered data remains.

public override ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken)

ValueTask<string>