Skip to content

Hex1bAppWorkloadAdapter

Namespace: Hex1b

Assembly: Hex1b.dll

Workload adapter for Hex1bApp TUI applications. Bridges the raw byte interface of with the higher-level APIs that Hex1bApp needs.

csharp
public sealed class Hex1bAppWorkloadAdapter : IHex1bAppTerminalWorkloadAdapter, IHex1bTerminalTokenWorkloadAdapter, IHex1bTerminalWorkloadAdapter, IAsyncDisposable, IDisposable

Inheritance

ObjectHex1bAppWorkloadAdapter

Implements

Constructors

Hex1bAppWorkloadAdapter(IHex1bTerminalPresentationAdapter)

Creates a new app workload adapter connected to a presentation adapter.

Parameters:

csharp
public Hex1bAppWorkloadAdapter(IHex1bTerminalPresentationAdapter presentationAdapter)

Hex1bAppWorkloadAdapter(TerminalCapabilities?)

Creates a new app workload adapter.

Parameters:

csharp
public Hex1bAppWorkloadAdapter(TerminalCapabilities? capabilities = null)

Properties

Capabilities

Terminal capabilities. Returns live capabilities from presentation adapter if available, otherwise returns the static capabilities provided at construction.

Returns: TerminalCapabilities

csharp
public TerminalCapabilities Capabilities { get; }

Height

Current terminal height.

Returns: Int32

csharp
public int Height { get; }

InputEvents

Channel of parsed input events from the terminal.

Returns: ChannelReader<Hex1bEvent>

csharp
public ChannelReader<Hex1bEvent> InputEvents { get; }

OutputQueueDepth

Gets the number of output items waiting to be consumed by the terminal. Can be used to detect back pressure and adjust input processing accordingly.

Returns: Int32

csharp
public int OutputQueueDepth { get; }

Width

Current terminal width.

Returns: Int32

csharp
public int Width { get; }

Methods

Clear()

Clear the screen.

csharp
public void Clear()

Dispose()

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

csharp
public void Dispose()

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()

EnterTuiMode()

Enter TUI mode. Writes standard ANSI sequences for alternate screen, hide cursor, enable mouse.

csharp
public void EnterTuiMode()

ExitTuiMode()

Exit TUI mode. Restores terminal state.

csharp
public void ExitTuiMode()

Flush()

Flush any buffered output.

csharp
public void Flush()

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)

ReadOutputItemAsync(CancellationToken)

Read output FROM the workload, optionally including a pre-tokenized representation.

Parameters:

Returns: ValueTask<WorkloadOutputItem>

A workload output item containing bytes and optional tokens.

csharp
public ValueTask<WorkloadOutputItem> ReadOutputItemAsync(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)

SendKey(ConsoleKey, char, bool, bool, bool)

Injects a key input event (for testing).

Parameters:

csharp
public void SendKey(ConsoleKey key, char keyChar = '\0', bool shift = false, bool alt = false, bool control = false)

SendKey(Hex1bKey, char, Hex1bModifiers)

Injects a key input event using Hex1bKey (for testing).

Parameters:

csharp
public void SendKey(Hex1bKey key, char keyChar = '\0', Hex1bModifiers modifiers = Hex1bModifiers.None)

SendMouse(MouseButton, MouseAction, int, int, Hex1bModifiers, int)

Injects a mouse input event (for testing).

Parameters:

csharp
public void SendMouse(MouseButton button, MouseAction action, int x, int y, Hex1bModifiers modifiers = Hex1bModifiers.None, int clickCount = 1)

SetCursorPosition(int, int)

Set the cursor position.

Parameters:

csharp
public void SetCursorPosition(int left, int top)

TryReadOutput(out ReadOnlyMemory<byte>)

Tries to read output without blocking. Returns true if data was available.

Parameters:

Returns: Boolean

True if data was available, false otherwise.

csharp
public bool TryReadOutput(out ReadOnlyMemory<byte> data)

TryWriteInputEvent(Hex1bEvent)

Write a parsed input event directly (synchronous).

Parameters:

Returns: Boolean

csharp
public bool TryWriteInputEvent(Hex1bEvent evt)

TypeText(string)

Types a string of characters (for testing).

Parameters:

csharp
public void TypeText(string text)

Write(ReadOnlyMemory<byte>)

Write raw bytes to the terminal without forcing a copy.

Parameters:

csharp
public void Write(ReadOnlyMemory<byte> data)

Write(ReadOnlySpan<byte>)

Write raw bytes to the terminal.

Parameters:

csharp
public void Write(ReadOnlySpan<byte> data)

Write(string)

Write ANSI-encoded output to the terminal.

Parameters:

csharp
public void Write(string text)

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)

WriteInputEventAsync(Hex1bEvent, CancellationToken)

Write a parsed input event directly (used by Hex1bTerminal after parsing).

Parameters:

Returns: ValueTask

csharp
public ValueTask WriteInputEventAsync(Hex1bEvent evt, CancellationToken ct = default)

Events

Disconnected

Raised when workload has disconnected/exited.

Returns: Action

csharp
public event Action? Disconnected

Remarks

This adapter has two faces: Terminal side: Implements for Hex1bTerminalApp side: Provides , , etc. for Hex1bApp

Data flow: App calls Write() → bytes queued → Terminal calls ReadOutputAsync()Terminal calls WriteInputAsync() → parsed to events → App reads InputEvents

Examples

csharp
var workload = new Hex1bAppWorkloadAdapter();
var terminal = new Hex1bTerminal(workload, 80, 24);
var app = new Hex1bApp(workload, ctx => ctx.Text("Hello"));
await app.RunAsync();

Released under the MIT License.