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.
public sealed class CharacterBindingInheritance
Object → CharacterBinding
Constructors
CharacterBinding(Func<string, bool>, Action<string>, string?, ActionId?)
Creates a text binding with the given predicate and synchronous handler.
Parameters:
predicate(Func<String, Boolean>):handler(Action<String>):description(String):actionId(Nullable<ActionId>):
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:
predicate(Func<String, Boolean>):handler(Func<String, InputBindingActionContext, Task>):description(String):actionId(Nullable<ActionId>):
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>
public ActionId? ActionId { get; }AsyncHandler
The async action to execute when matching text input is received.
Returns: Func<String, InputBindingActionContext, Task>
public Func<string, InputBindingActionContext, Task>? AsyncHandler { get; }Description
Optional description for this binding (for help/documentation).
Returns: String
public string? Description { get; }Handler
The synchronous action to execute when matching text input is received.
Returns: Action<String>
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>
public Func<string, bool> Predicate { get; }Methods
Execute(string)
Executes the binding's handler with the given text.
Parameters:
text(String):
public void Execute(string text)ExecuteAsync(string, InputBindingActionContext)
Executes the binding's async handler with the given text and context.
Parameters:
text(String):context(InputBindingActionContext):
Returns: Task
public Task ExecuteAsync(string text, InputBindingActionContext context)Matches(string)
Checks if this binding matches the given text.
Parameters:
text(String):
Returns: Boolean
public bool Matches(string text)