using System.Text;
namespace Febe.Core.Collection.Recipes;
///
/// What the focus check of the site's search box says (issue #37). Never the text: only whether the box is on the
/// page, whether the focus is in it, how many characters it holds and whether the caret is at the end.
///
/// The search box is on the page and visible.
/// The focus is in the box.
/// Characters in the box, only when the focus is in it (null otherwise).
/// The caret is at the end of the text, with nothing selected.
public sealed record SearchFocus(bool BoxFound, bool Focused, int? Length, bool CaretAtEnd)
{
/// No box on the page.
public static SearchFocus None { get; } = new(false, false, null, false);
/// The box has the focus and the caret is at the end: keys go where Febe wants them.
public bool Ready => BoxFound && Focused && Length is not null && CaretAtEnd;
private bool PrintMembers(StringBuilder builder)
{
builder.Append($"BoxFound = {BoxFound}, Focused = {Focused}, Length = {Length}, CaretAtEnd = {CaretAtEnd}");
return true;
}
}
///
/// Typing into the site's own search box (issue #37), with Input.dispatchKeyEvent only: letters, digits,
/// «.», «_» and spaces, Backspace and End, never Enter, Tab or Escape. Separate from , which
/// the recipes use: only the profile search types.
///
public interface ISearchInput
{
/// The read-only focus check of the search box.
Task FocusAsync(CancellationToken ct);
/// Presses End: the caret goes to the end of the text.
Task EndKeyAsync(CancellationToken ct);
///
/// Presses Backspace times at a human rhythm; runs right
/// before every key (the search notes where the page's requests stand).
///
Task EraseAsync(int count, Action? beforeKey, CancellationToken ct);
///
/// Types the characters gives, one at a time at a human rhythm, until it returns null.
/// receives how many characters were typed so far, and may run its own checks (it is
/// awaited before every key). Returns how many characters were typed. A character outside the closed key map stops
/// the burst with before its key is sent.
///
Task TypeAsync(Func> next, CancellationToken ct);
}