Skip to content

RemoteTerminalWorkloadAdapter

Namespace: Hex1b

Assembly: Hex1b.dll

A workload adapter that connects to a remote terminal host over WebSocket. The remote host exposes itself via WebSocketDiagnosticsListener at a /ws/attach endpoint. This adapter bridges the WebSocket I/O to the contract so a local can display and interact with the remote terminal.

csharp
public sealed class RemoteTerminalWorkloadAdapter : IHex1bTerminalWorkloadAdapter, IAsyncDisposable

Inheritance

ObjectRemoteTerminalWorkloadAdapter

Implements

Constructors

RemoteTerminalWorkloadAdapter(Uri)

Creates a new remote terminal workload adapter.

Parameters:

  • uri (Uri): WebSocket URI to connect to (e.g. ws://localhost:8080/ws/attach).
csharp
public RemoteTerminalWorkloadAdapter(Uri uri)

Properties

IsLeader

Gets whether this client is the resize leader.

Returns: Boolean

csharp
public bool IsLeader { get; }

RemoteHeight

Gets the remote terminal height reported during the handshake.

Returns: Int32

csharp
public int RemoteHeight { get; }

RemoteWidth

Gets the remote terminal width reported during the handshake.

Returns: Int32

csharp
public int RemoteWidth { 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)

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

Use this adapter via the builder API:

csharp
await using var terminal = Hex1bTerminal.CreateBuilder()
    .WithRemoteTerminal(new Uri("ws://localhost:8080/ws/attach"))
    .Build();

await terminal.RunAsync();

Protocol: binary WebSocket frames carry raw terminal I/O bytes. JSON text frames carry control messages (resize, leader, exit).

Released under the MIT License.