Skip to content

Hwt1PresentationAdapter

Namespace: Hex1b

Assembly: Hex1b.dll

Presents authoritative terminal state to Hex1b's first-party browser client using HWT1.

csharp
public sealed class Hwt1PresentationAdapter : ICellImpactAwarePresentationAdapter, ITerminalLifecycleAwarePresentationAdapter, IHex1bTerminalPresentationAdapter, IAsyncDisposable, ITerminalReflowProvider

Inheritance

ObjectHwt1PresentationAdapter

Implements

Constructors

Hwt1PresentationAdapter(int, int)

Creates an HWT1 presentation adapter with the initial grid dimensions.

Parameters:

  • width (Int32): Initial width, from 20 to 300 columns.
  • height (Int32): Initial height, from 10 to 100 rows.
csharp
public Hwt1PresentationAdapter(int width = 80, int height = 24)

Properties

AcknowledgementTimeout

Gets the maximum time the next frame read waits for the previous acknowledgement. Defaults to two minutes.

Returns: TimeSpan

csharp
public TimeSpan AcknowledgementTimeout { get; init; }

Capabilities

Capability hints that inform optimization strategies.

Returns: TerminalCapabilities

csharp
public TerminalCapabilities Capabilities { get; }

Height

Current terminal height in rows.

Returns: Int32

csharp
public int Height { get; }

IsReadOnly

Gets or sets whether this view ignores client commands that modify the producer. Defaults to false.

Returns: Boolean

csharp
public bool IsReadOnly { get; set; }

ReflowEnabled

Gets whether reflow is enabled. When false, the terminal uses standard crop-and-extend resize behavior even though the adapter implements this interface. Defaults to true.

Returns: Boolean

csharp
public bool ReflowEnabled { get; }

ShouldClearSoftWrapOnAbsolutePosition

Gets whether absolute cursor positioning (CUP, HVP) should clear the flag on the current row's last cell.

Returns: Boolean

csharp
public bool ShouldClearSoftWrapOnAbsolutePosition { get; }

Width

Current terminal width in columns.

Returns: Int32

csharp
public int Width { get; }

Methods

DisposeAsync()

Disconnects this adapter and cancels pending frame, input, and acknowledgement waits.

Returns: ValueTask

An operation that completes after the view's HMP1 peer, if any, is disconnected.

csharp
public ValueTask DisposeAsync()

EnterRawModeAsync(CancellationToken)

Enter raw mode for proper input capture.

Parameters:

Returns: ValueTask

csharp
public ValueTask EnterRawModeAsync(CancellationToken ct = default)

ExitRawModeAsync(CancellationToken)

Exit raw mode and restore normal terminal input handling.

Parameters:

Returns: ValueTask

csharp
public ValueTask ExitRawModeAsync(CancellationToken ct = default)

FlushAsync(CancellationToken)

Flush any buffered output immediately.

Parameters:

Returns: ValueTask

csharp
public ValueTask FlushAsync(CancellationToken ct = default)

GetCursorPosition()

Gets the current cursor position in the terminal. Returns (0, 0) if the position cannot be determined.

Returns: ValueTuple<Int32, Int32>

A tuple of (Row, Column), both 0-based.

csharp
public (int Row, int Column) GetCursorPosition()

HandleMessageAsync(ReadOnlyMemory<byte>, CancellationToken)

Processes one complete UTF-8 HWT1 client JSON message.

Parameters:

  • utf8Json (ReadOnlyMemory<Byte>): An acknowledgement, resync, resize, requestPrimary, input, paste, key, mouse, viewport, selection, or copy message, at most 64 KiB.
  • cancellationToken (CancellationToken): Cancels processing and workload input writes.

Returns: Task

A task that completes when the message has been handled.

csharp
public Task HandleMessageAsync(ReadOnlyMemory<byte> utf8Json, CancellationToken cancellationToken = default)

InvalidatePresentation()

Notifies the presentation that terminal state changed without producing output bytes.

csharp
public void InvalidatePresentation()

ReadFrameAsync(CancellationToken)

Reads the next complete HWT1 state frame.

Parameters:

  • cancellationToken (CancellationToken): Cancels this read without acknowledging any frame.

Returns: ValueTask<Byte>>

The complete binary frame, whose memory remains valid after subsequent reads.

csharp
public ValueTask<ReadOnlyMemory<byte>> ReadFrameAsync(CancellationToken cancellationToken = default)

ReadInputAsync(CancellationToken)

Receive input (keystrokes, mouse events as ANSI sequences) FROM the user.

Parameters:

Returns: ValueTask<Byte>>

Raw input bytes from the user, or empty when disconnected.

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

Reflow(ReflowContext)

Performs reflow of terminal content during a resize operation.

Parameters:

  • context (ReflowContext): The current terminal state including screen buffer, scrollback, and cursor position.

Returns: ReflowResult

The reflowed terminal state with new buffer, scrollback, and cursor position.

csharp
public ReflowResult Reflow(ReflowContext context)

TerminalCompleted(int)

Called when the terminal has completed execution.

Parameters:

  • exitCode (Int32): The exit code from the terminal's run callback or workload.
csharp
public void TerminalCompleted(int exitCode)

TerminalCreated(Hex1bTerminal)

Called when the terminal instance is created and associated with this adapter.

Parameters:

csharp
public void TerminalCreated(Hex1bTerminal terminal)

TerminalStarted()

Called when the terminal has started and is ready to process I/O.

csharp
public void TerminalStarted()

WithReflow(ITerminalReflowProvider)

Enables reflow when this adapter is attached directly to a terminal. By default, resize crops the screen without reflow.

Parameters:

Returns: Hwt1PresentationAdapter

This adapter for fluent configuration before terminal construction.

csharp
public Hwt1PresentationAdapter WithReflow(ITerminalReflowProvider strategy)

WriteOutputAsync(ReadOnlyMemory<byte>, CancellationToken)

Write rendered output TO the presentation layer (display).

Parameters:

Returns: ValueTask

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

WriteOutputWithImpactsAsync(IReadOnlyList<AppliedToken>, CancellationToken)

Called when output is being sent to the presentation layer, with cell impact information.

Parameters:

Returns: ValueTask

A task that completes when the output has been processed.

csharp
public ValueTask WriteOutputWithImpactsAsync(IReadOnlyList<AppliedToken> appliedTokens, CancellationToken ct = default)

Events

Disconnected

Raised when the presentation layer disconnects (e.g., terminal closed, WebSocket dropped).

Returns: Action

csharp
public event Action? Disconnected

Resized

Raised when the presentation layer is resized by the user.

Returns: Action<Int32, Int32>

csharp
public event Action<int, int>? Resized

Remarks

Attach one adapter to one terminal and one ordered, message-preserving connection. Send each result of as a complete binary message, and concurrently deliver client JSON messages to in transport order. The adapter owns projection, resources, acknowledgements, resync, and mode-aware input; the host owns transport, authentication, and terminal lifetime. No ASP.NET or WebSocket dependency is required. HWT1 is internal state transfer, not a supported contract for third-party frontend implementations. Keep the server and first-party client in sync and upgrade them together. The wire format may change without backward-compatibility or deprecation guarantees; its name and version field do not imply cross-release compatibility. This API is also experimental. The current client-requested profile uses 10x20 logical-pixel cells, 20..300 columns, and 10..100 rows. A directly attached supplies authoritative geometry and primary ownership instead; producer dimensions are not clamped to this request profile. Frames support up to 1024 columns, 512 rows, and 262144 total cells. Larger authoritative grids fail projection without resizing the producer. Reconnection requires a new adapter; resync repairs the existing connection only. Producer-backed views can be created with . Each connection owns its viewport and selection. Historical rendering is text-only, bounded to the producer's current grid; older, wider rows are cropped visually, but logical-line and normal multirow extraction retain their original widths and soft wraps. Resize, reflow, reset, and buffer switches invalidate selection coordinates explicitly. Erased or discarded selected rows also invalidate the whole selection. Output does not move a retained historical anchor. Keyboard input and paste clear selection and return live. Rewriting selected live text invalidates the selection before extension or copying; character writes and cell-level erases outside the selected span preserve its captured intent. Structural row operations conservatively invalidate selections touching affected rows. Selected text is bounded to 512 Ki UTF-16 code units (including padding before trimming). Word and logical-line expansion enforce this bound during traversal. An oversized selection is explicitly invalidated rather than copied partially. Frames also carry the captured , including an empty title. Title-only output can produce a frame with no changed cells. Titles follow the same coalescing and synchronized-output rules as other state; frames are not a lossless stream of individual title-setting sequences. Progress and shell-integration state use the same snapshot and coalescing rules. These fields are current even when the view is displaying historical text.

Released under the MIT License.