Skip to content

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.

csharp
public sealed class PasteContext : IAsyncDisposable

Inheritance

ObjectPasteContext

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

csharp
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

csharp
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

csharp
public Action Invalidate { get; }

IsCancelled

Whether the paste was cancelled before the end marker was received.

Returns: Boolean

csharp
public bool IsCancelled { get; }

IsCompleted

Whether the paste has finished receiving data (end marker received).

Returns: Boolean

csharp
public bool IsCompleted { get; }

TotalCharactersWritten

Total number of characters written to the paste context so far.

Returns: Int64

csharp
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~.

csharp
public void Cancel()

CopyToAsync(Stream, Encoding?, CancellationToken)

Copy all paste data to a destination stream as it arrives.

Parameters:

Returns: Task

csharp
public Task CopyToAsync(Stream destination, Encoding? encoding = null, CancellationToken ct = default)

DisposeAsync()

Disposes the PasteContext, cancelling any pending operations.

Returns: ValueTask

csharp
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:

Returns: IAsyncEnumerable<String>

csharp
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:

Returns: IAsyncEnumerable<String>

csharp
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.

csharp
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:

Returns: Task

csharp
public Task SaveToFileAsync(string path, Encoding? encoding = null, CancellationToken ct = default)

Released under the MIT License.