Skip to content

CharacterBinding

Namespace: Hex1b.Input

Assembly: Hex1b.dll

Represents a binding that matches text input based on a predicate. Used for handling arbitrary printable text input in widgets like TextBox. Supports both single characters and multi-char sequences like emojis.

csharp
public sealed class CharacterBinding

Inheritance

ObjectCharacterBinding

Constructors

CharacterBinding(Func<string, bool>, Action<string>, string?, ActionId?)

Creates a text binding with the given predicate and synchronous handler.

Parameters:

csharp
public CharacterBinding(Func<string, bool> predicate, Action<string> handler, string? description = null, ActionId? actionId = null)

CharacterBinding(Func<string, bool>, Func<string, InputBindingActionContext, Task>, string?, ActionId?)

Creates a text binding with the given predicate and async handler.

Parameters:

csharp
public CharacterBinding(Func<string, bool> predicate, Func<string, InputBindingActionContext, Task> handler, string? description = null, ActionId? actionId = null)

Properties

ActionId

A stable identifier for the action this binding performs. Used for programmatic rebinding via .

Returns: Nullable<ActionId>

csharp
public ActionId? ActionId { get; }

AsyncHandler

The async action to execute when matching text input is received.

Returns: Func<String, InputBindingActionContext, Task>

csharp
public Func<string, InputBindingActionContext, Task>? AsyncHandler { get; }

Description

Optional description for this binding (for help/documentation).

Returns: String

csharp
public string? Description { get; }

Handler

The synchronous action to execute when matching text input is received.

Returns: Action<String>

csharp
public Action<string>? Handler { get; }

Predicate

Predicate that determines if a text input should be handled. Common predicates: text => text.Length > 0 && !char.IsControl(text[0]) for printable text.

Returns: Func<String, Boolean>

csharp
public Func<string, bool> Predicate { get; }

Methods

Execute(string)

Executes the binding's handler with the given text.

Parameters:

csharp
public void Execute(string text)

ExecuteAsync(string, InputBindingActionContext)

Executes the binding's async handler with the given text and context.

Parameters:

Returns: Task

csharp
public Task ExecuteAsync(string text, InputBindingActionContext context)

Matches(string)

Checks if this binding matches the given text.

Parameters:

Returns: Boolean

csharp
public bool Matches(string text)

Released under the MIT License.