Skip to content

AsciinemaFileWorkloadAdapter

Namespace: Hex1b

Assembly: Hex1b.dll

A workload adapter that plays back an asciinema (.cast) recording file.

csharp
public sealed class AsciinemaFileWorkloadAdapter : IHex1bTerminalWorkloadAdapter, IAsyncDisposable

Inheritance

ObjectAsciinemaFileWorkloadAdapter

Implements

Constructors

AsciinemaFileWorkloadAdapter(string)

Creates a new asciinema file workload adapter.

Parameters:

  • filePath (String): Path to the .cast file to play back.
csharp
public AsciinemaFileWorkloadAdapter(string filePath)

Properties

Height

Gets the height from the asciinema header, or 0 if not yet read.

Returns: Int32

csharp
public int Height { get; }

SpeedMultiplier

Gets or sets the playback speed multiplier. Default is 1.0 (normal speed). Set to 2.0 for 2x speed, 0.5 for half speed, etc.

Returns: Double

csharp
public double SpeedMultiplier { get; set; }

Width

Gets the width from the asciinema header, or 0 if not yet read.

Returns: Int32

csharp
public int Width { get; }

Methods

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

Returns: ValueTask

A task that represents the asynchronous dispose operation.

csharp
public ValueTask DisposeAsync()

ReadOutputAsync(CancellationToken)

Read output FROM the workload (ANSI sequences to display). The terminal calls this to get data to parse and send to presentation. Returns empty when workload has no more output (should be called in a loop).

Parameters:

Returns: ValueTask<Byte>>

csharp
public ValueTask<ReadOnlyMemory<byte>> ReadOutputAsync(CancellationToken ct = default)

ResizeAsync(int, int, CancellationToken)

Notify workload of terminal resize.

Parameters:

Returns: ValueTask

csharp
public ValueTask ResizeAsync(int width, int height, CancellationToken ct = default)

StartAsync(CancellationToken)

Starts playback of the asciinema file.

Parameters:

Returns: Task

csharp
public Task StartAsync(CancellationToken ct = default)

WriteInputAsync(ReadOnlyMemory<byte>, CancellationToken)

Write input TO the workload (raw bytes from keyboard/mouse). The terminal calls this when it receives input from the presentation layer.

Parameters:

Returns: ValueTask

csharp
public ValueTask WriteInputAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)

Events

Disconnected

Raised when workload has disconnected/exited.

Returns: Action

csharp
public event Action? Disconnected

Remarks

This adapter reads asciicast v2 format files and replays the terminal output with proper timing. It's useful for:

Playing back recorded terminal sessionsCreating demos and tutorials from recordingsTesting terminal rendering with real-world dataConverting asciinema files to other formats

The adapter reads events from the file and streams them at the appropriate times based on the timestamps in the recording. Output events ("o" type) are converted to bytes and returned via . Resize events ("r" type) trigger the callback.

Examples

csharp
await using var terminal = Hex1bTerminal.CreateBuilder()
    .WithAsciinemaPlayback("recording.cast")
    .Build();

await terminal.RunAsync();

Released under the MIT License.