using System.Collections.ObjectModel;
namespace Terminal.Gui;
///
/// Abstract implementation of allows for tailoring how autocomplete is
/// rendered/interacted with.
///
public abstract class AutocompleteBase : IAutocomplete
{
///
public abstract View HostControl { get; set; }
///
public bool PopupInsideContainer { get; set; }
///
public ISuggestionGenerator SuggestionGenerator { get; set; } = new SingleWordSuggestionGenerator ();
///
public virtual int MaxWidth { get; set; } = 10;
///
public virtual int MaxHeight { get; set; } = 6;
///
///
public virtual bool Visible { get; set; }
///
public virtual ReadOnlyCollection Suggestions { get; set; } = new (new Suggestion [0]);
///
public virtual int SelectedIdx { get; set; }
///
public abstract ColorScheme ColorScheme { get; set; }
///
public virtual Key SelectionKey { get; set; } = Key.Enter;
///
public virtual Key CloseKey { get; set; } = Key.Esc;
///
public virtual Key Reopen { get; set; } = Key.Space.WithCtrl.WithAlt;
///
public virtual AutocompleteContext Context { get; set; }
///
public abstract bool OnMouseEvent (MouseEventArgs me, bool fromHost = false);
///
public abstract bool ProcessKey (Key a);
///
public abstract void RenderOverlay (Point renderAt);
///
/// >
public virtual void ClearSuggestions () { Suggestions = Enumerable.Empty ().ToList ().AsReadOnly (); }
///
public virtual void GenerateSuggestions (AutocompleteContext context)
{
Suggestions = SuggestionGenerator.GenerateSuggestions (context).ToList ().AsReadOnly ();
EnsureSelectedIdxIsValid ();
}
/// Updates to be a valid index within
public virtual void EnsureSelectedIdxIsValid () { SelectedIdx = Math.Max (0, Math.Min (Suggestions.Count - 1, SelectedIdx)); }
}