WebSocketPresentationAdapter
Namespace: Hex1b
Assembly: Hex1b.dll
WebSocket presentation adapter for browser-based terminal connections.
public sealed class WebSocketPresentationAdapter : IHex1bTerminalPresentationAdapter, IAsyncDisposableInheritance
Object → WebSocketPresentationAdapter
Implements
Constructors
WebSocketPresentationAdapter(WebSocket, int, int, bool)
Creates a new WebSocket presentation adapter.
Parameters:
webSocket(WebSocket): The WebSocket connection to use.width(Int32): Initial terminal width in columns.height(Int32): Initial terminal height in rows.enableMouse(Boolean): Whether to enable mouse tracking.
public WebSocketPresentationAdapter(WebSocket webSocket, int width, int height, bool enableMouse = false)Properties
Capabilities
Capability hints that inform optimization strategies.
Returns: TerminalCapabilities
public TerminalCapabilities Capabilities { get; }Height
Current terminal height in rows.
Returns: Int32
public int Height { get; }Width
Current terminal width in columns.
Returns: Int32
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.
public ValueTask DisposeAsync()EnterRawModeAsync(CancellationToken)
Enter raw mode for proper input capture.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: ValueTask
public ValueTask EnterRawModeAsync(CancellationToken ct = default)ExitRawModeAsync(CancellationToken)
Exit raw mode and restore normal terminal input handling.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: ValueTask
public ValueTask ExitRawModeAsync(CancellationToken ct = default)FlushAsync(CancellationToken)
Flush any buffered output immediately.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: ValueTask
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.
public (int Row, int Column) GetCursorPosition()ReadInputAsync(CancellationToken)
Receive input (keystrokes, mouse events as ANSI sequences) FROM the user.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: ValueTask<Byte>>
Raw input bytes from the user, or empty when disconnected.
public ValueTask<ReadOnlyMemory<byte>> ReadInputAsync(CancellationToken ct = default)Resize(int, int, int?, int?, double?)
Updates the terminal dimensions, typically called when receiving a resize message from the client.
Parameters:
width(Int32): New terminal width in columns.height(Int32): New terminal height in rows.cellPixelWidth(Nullable<Int32>): Optional cell width in pixels (integer).cellPixelHeight(Nullable<Int32>): Optional cell height in pixels.actualCellPixelWidth(Nullable<Double>): Optional actual (floating-point) cell width.
public void Resize(int width, int height, int? cellPixelWidth = null, int? cellPixelHeight = null, double? actualCellPixelWidth = null)WriteOutputAsync(ReadOnlyMemory<byte>, CancellationToken)
Write rendered output TO the presentation layer (display).
Parameters:
data(ReadOnlyMemory<Byte>): The output data to send to the display.ct(CancellationToken): Cancellation token.
Returns: ValueTask
public ValueTask WriteOutputAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)Events
Disconnected
Raised when the presentation layer disconnects (e.g., terminal closed, WebSocket dropped).
Returns: Action
public event Action? DisconnectedResized
Raised when the presentation layer is resized by the user.
Returns: Action<Int32, Int32>
public event Action<int, int>? ResizedRemarks
This adapter implements for WebSocket connections, allowing Hex1b applications to run in web browsers through xterm.js or similar terminal emulators.