PasteContext
Namespace: Hex1b.Input
Assembly: Hex1b.dll
Provides streaming access to bracketed paste data. Created when a paste start marker (ESC[200~) is detected, data is written as it arrives, and completed when the end marker (ESC[201~) is received.
public sealed class PasteContext : IAsyncDisposableInheritance
Object → PasteContext
Implements
Properties
CancellationToken
Cancellation token that is signaled when the paste is cancelled (by user Escape, timeout, size limit, or programmatic Cancel() call).
Returns: CancellationToken
public CancellationToken CancellationToken { get; }Completed
A task that completes when the paste end marker (ESC[201~) is received or the paste is cancelled.
Returns: Task
public Task Completed { get; }Invalidate
Request a UI re-render. Safe to call from any thread. Call this from your paste handler when you have UI updates to show (e.g., progress).
Returns: Action
public Action Invalidate { get; }IsCancelled
Whether the paste was cancelled before the end marker was received.
Returns: Boolean
public bool IsCancelled { get; }IsCompleted
Whether the paste has finished receiving data (end marker received).
Returns: Boolean
public bool IsCompleted { get; }TotalCharactersWritten
Total number of characters written to the paste context so far.
Returns: Int64
public long TotalCharactersWritten { get; }Methods
Cancel()
Cancel the paste. The handler's async enumerables will stop yielding. Remaining paste data from the terminal is drained and discarded until ESC[201~.
public void Cancel()CopyToAsync(Stream, Encoding?, CancellationToken)
Copy all paste data to a destination stream as it arrives.
Parameters:
destination(Stream): The stream to write to.encoding(Encoding): Text encoding to use. Defaults to UTF-8.ct(CancellationToken): Cancellation token.
Returns: Task
public Task CopyToAsync(Stream destination, Encoding? encoding = null, CancellationToken ct = default)DisposeAsync()
Disposes the PasteContext, cancelling any pending operations.
Returns: ValueTask
public ValueTask DisposeAsync()ReadChunksAsync(CancellationToken)
Read paste data chunk-by-chunk as it arrives from the terminal. Each chunk corresponds to one or more tokens from a single terminal read.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: IAsyncEnumerable<String>
public IAsyncEnumerable<string> ReadChunksAsync(CancellationToken ct = default)ReadLinesAsync(CancellationToken)
Read paste data line-by-line as lines become available. Handles line endings: \n, \r\n, \r.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: IAsyncEnumerable<String>
public IAsyncEnumerable<string> ReadLinesAsync(CancellationToken ct = default)ReadToEndAsync(int, CancellationToken)
Read the entire paste content as a string. Best for small pastes. For large pastes, prefer or .
Parameters:
maxCharacters(Int32): Maximum number of characters to read. Throws if exceeded.ct(CancellationToken): Cancellation token.
Returns: Task<String>
The complete paste text.
public Task<string> ReadToEndAsync(int maxCharacters = 4194304, CancellationToken ct = default)SaveToFileAsync(string, Encoding?, CancellationToken)
Save all paste data to a file as it arrives.
Parameters:
path(String): The file path to write to.encoding(Encoding): Text encoding to use. Defaults to UTF-8.ct(CancellationToken): Cancellation token.
Returns: Task
public Task SaveToFileAsync(string path, Encoding? encoding = null, CancellationToken ct = default)