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.
public sealed class Hex1bAppWorkloadAdapter : IHex1bAppTerminalWorkloadAdapter, IHex1bTerminalTokenWorkloadAdapter, IHex1bTerminalWorkloadAdapter, IAsyncDisposable, IDisposableInheritance
Object → Hex1bAppWorkloadAdapter
Implements
- IHex1bAppTerminalWorkloadAdapter
- IHex1bTerminalTokenWorkloadAdapter
- IHex1bTerminalWorkloadAdapter
- IAsyncDisposable
- IDisposable
Constructors
Hex1bAppWorkloadAdapter(IHex1bTerminalPresentationAdapter)
Creates a new app workload adapter connected to a presentation adapter.
Parameters:
presentationAdapter(IHex1bTerminalPresentationAdapter): The presentation adapter to delegate capabilities to.
public Hex1bAppWorkloadAdapter(IHex1bTerminalPresentationAdapter presentationAdapter)Hex1bAppWorkloadAdapter(TerminalCapabilities?)
Creates a new app workload adapter.
Parameters:
capabilities(TerminalCapabilities): Terminal capabilities. If null, defaults with full support.
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
public TerminalCapabilities Capabilities { get; }Height
Current terminal height.
Returns: Int32
public int Height { get; }InputEvents
Channel of parsed input events from the terminal.
Returns: ChannelReader<Hex1bEvent>
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
public int OutputQueueDepth { get; }Width
Current terminal width.
Returns: Int32
public int Width { get; }Methods
Clear()
Clear the screen.
public void Clear()Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
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.
public ValueTask DisposeAsync()EnterTuiMode()
Enter TUI mode. Writes standard ANSI sequences for alternate screen, hide cursor, enable mouse.
public void EnterTuiMode()ExitTuiMode()
Exit TUI mode. Restores terminal state.
public void ExitTuiMode()Flush()
Flush any buffered output.
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:
ct(CancellationToken):
Returns: ValueTask<Byte>>
public ValueTask<ReadOnlyMemory<byte>> ReadOutputAsync(CancellationToken ct = default)ReadOutputItemAsync(CancellationToken)
Read output FROM the workload, optionally including a pre-tokenized representation.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: ValueTask<WorkloadOutputItem>
A workload output item containing bytes and optional tokens.
public ValueTask<WorkloadOutputItem> ReadOutputItemAsync(CancellationToken ct = default)ResizeAsync(int, int, CancellationToken)
Notify workload of terminal resize.
Parameters:
width(Int32):height(Int32):ct(CancellationToken):
Returns: ValueTask
public ValueTask ResizeAsync(int width, int height, CancellationToken ct = default)SendKey(ConsoleKey, char, bool, bool, bool)
Injects a key input event (for testing).
Parameters:
key(ConsoleKey):keyChar(Char):shift(Boolean):alt(Boolean):control(Boolean):
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:
key(Hex1bKey):keyChar(Char):modifiers(Hex1bModifiers):
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:
button(MouseButton):action(MouseAction):x(Int32):y(Int32):modifiers(Hex1bModifiers):clickCount(Int32):
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:
public void SetCursorPosition(int left, int top)TryReadOutput(out ReadOnlyMemory<byte>)
Tries to read output without blocking. Returns true if data was available.
Parameters:
data(ReadOnlyMemory<Byte>): The output data if available, or empty if not.
Returns: Boolean
True if data was available, false otherwise.
public bool TryReadOutput(out ReadOnlyMemory<byte> data)TryWriteInputEvent(Hex1bEvent)
Write a parsed input event directly (synchronous).
Parameters:
evt(Hex1bEvent):
Returns: Boolean
public bool TryWriteInputEvent(Hex1bEvent evt)TypeText(string)
Types a string of characters (for testing).
Parameters:
text(String):
public void TypeText(string text)Write(ReadOnlyMemory<byte>)
Write raw bytes to the terminal without forcing a copy.
Parameters:
data(ReadOnlyMemory<Byte>):
public void Write(ReadOnlyMemory<byte> data)Write(ReadOnlySpan<byte>)
Write raw bytes to the terminal.
Parameters:
data(ReadOnlySpan<Byte>):
public void Write(ReadOnlySpan<byte> data)Write(string)
Write ANSI-encoded output to the terminal.
Parameters:
text(String):
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:
data(ReadOnlyMemory<Byte>):ct(CancellationToken):
Returns: ValueTask
public ValueTask WriteInputAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)WriteInputEventAsync(Hex1bEvent, CancellationToken)
Write a parsed input event directly (used by Hex1bTerminal after parsing).
Parameters:
evt(Hex1bEvent):ct(CancellationToken):
Returns: ValueTask
public ValueTask WriteInputEventAsync(Hex1bEvent evt, CancellationToken ct = default)Events
Disconnected
Raised when workload has disconnected/exited.
Returns: Action
public event Action? DisconnectedRemarks
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
var workload = new Hex1bAppWorkloadAdapter();
var terminal = new Hex1bTerminal(workload, 80, 24);
var app = new Hex1bApp(workload, ctx => ctx.Text("Hello"));
await app.RunAsync();