using System;
using System.Collections.ObjectModel;
using System.Linq;
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 ReadOnlyCollection (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 | Key.CtrlMask | Key.AltMask;
///
public abstract bool MouseEvent (MouseEvent me, bool fromHost = false);
///
public abstract bool ProcessKey (KeyEvent kb);
///
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));
}
}
}