Skip to content

Hex1bApp

Namespace: Hex1b

Assembly: Hex1b.dll

The main entry point for building terminal UI applications.

csharp
public class Hex1bApp : IDisposable, IAsyncDisposable

Inheritance

ObjectHex1bApp

Implements

Constructors

Hex1bApp(Func<RootContext, Hex1bWidget>, Hex1bAppOptions?)

Creates a Hex1bApp with a synchronous widget builder.

Parameters:

csharp
public Hex1bApp(Func<RootContext, Hex1bWidget> builder, Hex1bAppOptions? options = null)

Hex1bApp(Func<RootContext, Task<Hex1bWidget>>, Hex1bAppOptions?)

Creates a Hex1bApp with an async widget builder.

Parameters:

csharp
public Hex1bApp(Func<RootContext, Task<Hex1bWidget>> builder, Hex1bAppOptions? options = null)

Properties

CapturedNode

Gets the node that has captured all input, or null if no capture is active.

Returns: Hex1bNode

csharp
public Hex1bNode? CapturedNode { get; }

Focusables

Gets all focusable nodes in the current focus ring. Useful for testing and debugging focus navigation.

Returns: IReadOnlyList<Hex1bNode>

csharp
public IReadOnlyList<Hex1bNode> Focusables { get; }

FocusedNode

Gets the currently focused node, or null if no node has focus. Useful for testing and debugging focus state.

Returns: Hex1bNode

csharp
public Hex1bNode? FocusedNode { get; }

LastFocusChange

Gets the last focus change debug log from the focus ring. Useful for testing focus navigation.

Returns: String

csharp
public string? LastFocusChange { get; }

LastFocusDebug

Gets the last Focus() call debug log.

Returns: String

csharp
public string? LastFocusDebug { get; }

LastHitTestDebug

Gets the last hit test debug log from the focus ring. Useful for debugging mouse click focus issues.

Returns: String

csharp
public string? LastHitTestDebug { get; }

LastPathDebug

Gets the last path debug info from input routing.

Returns: String

csharp
public string? LastPathDebug { get; }

Methods

CaptureInput(Hex1bNode)

Captures all input to the specified node.

Parameters:

  • node (Hex1bNode): The node to capture input to.
csharp
public void CaptureInput(Hex1bNode node)

CopyToClipboard(string)

Copies the specified text to the system clipboard using the OSC 52 escape sequence.

Parameters:

  • text (String): The text to copy to the clipboard.
csharp
public void CopyToClipboard(string text)

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

FocusWhere(Func<Hex1bNode, bool>)

Focuses the first node in the focus ring that matches the given predicate.

Parameters:

Returns: Boolean

True if a matching node was found and focused, false otherwise.

csharp
public bool FocusWhere(Func<Hex1bNode, bool> predicate)

Invalidate()

Signals that the UI should be re-rendered. Call this when external state changes (network events, timers, etc.). This method is thread-safe and can be called from any thread.

csharp
public void Invalidate()

ReleaseCapture()

Releases input capture, returning to normal input routing.

csharp
public void ReleaseCapture()

RequestFocus(Func<Hex1bNode, bool>)

Requests that focus be set to the first node matching the predicate after the next render.

Parameters:

csharp
public void RequestFocus(Func<Hex1bNode, bool> predicate)

RequestStop()

Requests the application to stop. The RunAsync call will exit gracefully after the current frame completes.

csharp
public void RequestStop()

RunAsync(CancellationToken)

Runs the application until cancellation is requested.

Parameters:

Returns: Task

csharp
public Task RunAsync(CancellationToken cancellationToken = default)

Remarks

Hex1bApp manages the render loop, input handling, focus management, and reconciliation between widgets (immutable declarations) and nodes (mutable render state).

State management is handled via closures - simply capture your state variables in the widget builder callback.

Examples

Create a minimal Hex1b application:

csharp
using Hex1b;

var app = new Hex1bApp(ctx =>
    ctx.VStack(v => [
        v.Text("Hello, Hex1b!"),
        v.Button("Quit", e => e.Context.RequestStop())
    ])
);

await app.RunAsync();

Released under the MIT License.