diff --git a/src/Spectre.Console/Prompts/List/IListPromptStrategy.cs b/src/Spectre.Console/Prompts/List/IListPromptStrategy.cs index 2ecd0bc8c..3fdbbdc34 100644 --- a/src/Spectre.Console/Prompts/List/IListPromptStrategy.cs +++ b/src/Spectre.Console/Prompts/List/IListPromptStrategy.cs @@ -36,8 +36,8 @@ internal interface IListPromptStrategy /// Whether or not the list is scrollable. /// The cursor index. /// The visible items. - /// The search filter. + /// The search text. /// A representing the items. public IRenderable Render(IAnsiConsole console, bool scrollable, int cursorIndex, - IEnumerable<(int Index, ListPromptItem Node)> items, string searchFilter); + IEnumerable<(int Index, ListPromptItem Node)> items, string searchText); } \ No newline at end of file diff --git a/src/Spectre.Console/Prompts/List/ListPrompt.cs b/src/Spectre.Console/Prompts/List/ListPrompt.cs index 35c23069d..eb43d5266 100644 --- a/src/Spectre.Console/Prompts/List/ListPrompt.cs +++ b/src/Spectre.Console/Prompts/List/ListPrompt.cs @@ -15,7 +15,7 @@ public ListPrompt(IAnsiConsole console, IListPromptStrategy strategy) public async Task> Show( ListPromptTree tree, SelectionMode selectionMode, - bool searchFilterEnabled, + bool searchEnabled, int requestedPageSize, bool wrapAround, CancellationToken cancellationToken = default) @@ -40,7 +40,7 @@ public async Task> Show( } var nodes = tree.Traverse().ToList(); - var state = new ListPromptState(nodes, _strategy.CalculatePageSize(_console, nodes.Count, requestedPageSize), wrapAround, selectionMode, _strategy.ShouldSkipUnselectableItems, searchFilterEnabled); + var state = new ListPromptState(nodes, _strategy.CalculatePageSize(_console, nodes.Count, requestedPageSize), wrapAround, selectionMode, _strategy.ShouldSkipUnselectableItems, searchEnabled); var hook = new ListPromptRenderHook(_console, () => BuildRenderable(state)); using (new RenderHookScope(_console, hook)) @@ -112,6 +112,6 @@ private IRenderable BuildRenderable(ListPromptState state) scrollable, cursorIndex, state.Items.Skip(skip).Take(take) .Select((node, index) => (index, node)), - state.SearchFilter); + state.SearchText); } } \ No newline at end of file diff --git a/src/Spectre.Console/Prompts/List/ListPromptState.cs b/src/Spectre.Console/Prompts/List/ListPromptState.cs index 4910e6cbc..177b97edb 100644 --- a/src/Spectre.Console/Prompts/List/ListPromptState.cs +++ b/src/Spectre.Console/Prompts/List/ListPromptState.cs @@ -9,22 +9,22 @@ internal sealed class ListPromptState public bool WrapAround { get; } public SelectionMode Mode { get; } public bool SkipUnselectableItems { get; private set; } - public bool SearchFilterEnabled { get; } + public bool SearchEnabled { get; } public IReadOnlyList> Items { get; } private readonly IReadOnlyList? _leafIndexes; public ListPromptItem Current => Items[Index]; - public string SearchFilter { get; private set; } + public string SearchText { get; private set; } - public ListPromptState(IReadOnlyList> items, int pageSize, bool wrapAround, SelectionMode mode, bool skipUnselectableItems, bool searchFilterEnabled) + public ListPromptState(IReadOnlyList> items, int pageSize, bool wrapAround, SelectionMode mode, bool skipUnselectableItems, bool searchEnabled) { Items = items; PageSize = pageSize; WrapAround = wrapAround; Mode = mode; SkipUnselectableItems = skipUnselectableItems; - SearchFilterEnabled = searchFilterEnabled; - SearchFilter = string.Empty; + SearchEnabled = searchEnabled; + SearchText = string.Empty; if (SkipUnselectableItems && mode == SelectionMode.Leaf) { @@ -118,14 +118,14 @@ public bool Update(ConsoleKeyInfo keyInfo) }; } - var search = SearchFilter; + var search = SearchText; - if (SearchFilterEnabled) + if (SearchEnabled) { // If is text input, append to search filter if (!char.IsControl(keyInfo.KeyChar)) { - search = SearchFilter + keyInfo.KeyChar; + search = SearchText + keyInfo.KeyChar; var item = Items.FirstOrDefault(x => x.Data.ToString()?.Contains(search, StringComparison.OrdinalIgnoreCase) == true && (!x.IsGroup || Mode != SelectionMode.Leaf)); if (item != null) { @@ -152,10 +152,10 @@ public bool Update(ConsoleKeyInfo keyInfo) ? (ItemCount + (index % ItemCount)) % ItemCount : index.Clamp(0, ItemCount - 1); - if (index != Index || SearchFilter != search) + if (index != Index || SearchText != search) { Index = index; - SearchFilter = search; + SearchText = search; return true; } diff --git a/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs b/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs index 12b0fe971..1af03b3a9 100644 --- a/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs +++ b/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs @@ -226,7 +226,7 @@ int IListPromptStrategy.CalculatePageSize(IAnsiConsole console, int totalItem /// IRenderable IListPromptStrategy.Render(IAnsiConsole console, bool scrollable, int cursorIndex, - IEnumerable<(int Index, ListPromptItem Node)> items, string stateSearchFilter) + IEnumerable<(int Index, ListPromptItem Node)> items, string searchText) { var list = new List(); var highlightStyle = HighlightStyle ?? Color.Blue; diff --git a/src/Spectre.Console/Prompts/SelectionPrompt.cs b/src/Spectre.Console/Prompts/SelectionPrompt.cs index 58f2f16ed..08f4333c9 100644 --- a/src/Spectre.Console/Prompts/SelectionPrompt.cs +++ b/src/Spectre.Console/Prompts/SelectionPrompt.cs @@ -59,9 +59,9 @@ public sealed class SelectionPrompt : IPrompt, IListPromptStrategy public SelectionMode Mode { get; set; } = SelectionMode.Leaf; /// - /// Gets or sets a value indicating whether or not the search filter is enabled. + /// Gets or sets a value indicating whether or not search is enabled. /// - public bool SearchFilterEnabled { get; set; } + public bool SearchEnabled { get; set; } /// /// Initializes a new instance of the class. @@ -97,7 +97,7 @@ public async Task ShowAsync(IAnsiConsole console, CancellationToken cancellat { // Create the list prompt var prompt = new ListPrompt(console, this); - var result = await prompt.Show(_tree, Mode, SearchFilterEnabled, PageSize, WrapAround, cancellationToken).ConfigureAwait(false); + var result = await prompt.Show(_tree, Mode, SearchEnabled, PageSize, WrapAround, cancellationToken).ConfigureAwait(false); // Return the selected item return result.Items[result.Index].Data; @@ -132,12 +132,12 @@ int IListPromptStrategy.CalculatePageSize(IAnsiConsole console, int totalItem } var scrollable = totalItemCount > requestedPageSize; - if (SearchFilterEnabled || scrollable) + if (SearchEnabled || scrollable) { extra += 1; } - if (SearchFilterEnabled) + if (SearchEnabled) { extra += 1; } @@ -157,7 +157,7 @@ int IListPromptStrategy.CalculatePageSize(IAnsiConsole console, int totalItem /// IRenderable IListPromptStrategy.Render(IAnsiConsole console, bool scrollable, int cursorIndex, - IEnumerable<(int Index, ListPromptItem Node)> items, string stateSearchFilter) + IEnumerable<(int Index, ListPromptItem Node)> items, string searchText) { var list = new List(); var disabledStyle = DisabledStyle ?? Color.Grey; @@ -193,14 +193,14 @@ IRenderable IListPromptStrategy.Render(IAnsiConsole console, bool scrollable, text = text.RemoveMarkup().EscapeMarkup(); } - if (stateSearchFilter.Length > 0 && !(item.Node.IsGroup && Mode == SelectionMode.Leaf)) + if (searchText.Length > 0 && !(item.Node.IsGroup && Mode == SelectionMode.Leaf)) { - var index = text.IndexOf(stateSearchFilter, StringComparison.OrdinalIgnoreCase); + var index = text.IndexOf(searchText, StringComparison.OrdinalIgnoreCase); if (index >= 0) { var before = text.Substring(0, index); - var match = text.Substring(index, stateSearchFilter.Length); - var after = text.Substring(index + stateSearchFilter.Length); + var match = text.Substring(index, searchText.Length); + var after = text.Substring(index + searchText.Length); text = new StringBuilder() .Append(before) @@ -215,16 +215,16 @@ IRenderable IListPromptStrategy.Render(IAnsiConsole console, bool scrollable, list.Add(grid); - if (SearchFilterEnabled || scrollable) + if (SearchEnabled || scrollable) { // Add padding list.Add(Text.Empty); } - if (SearchFilterEnabled) + if (SearchEnabled) { list.Add(new Markup( - stateSearchFilter.Length > 0 ? stateSearchFilter.EscapeMarkup() : ListPromptConstants.SearchPlaceholderMarkup)); + searchText.Length > 0 ? searchText.EscapeMarkup() : ListPromptConstants.SearchPlaceholderMarkup)); } if (scrollable) diff --git a/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs b/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs index 40750c497..15cd4d72c 100644 --- a/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs +++ b/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs @@ -189,7 +189,7 @@ public static SelectionPrompt WrapAround(this SelectionPrompt obj, bool /// The prompt. /// Whether the search filter should be enabled. /// The same instance so that multiple calls can be chained. - public static SelectionPrompt SearchFilter(this SelectionPrompt obj, bool enabled = true) + public static SelectionPrompt Search(this SelectionPrompt obj, bool enabled = true) where T : notnull { if (obj is null) @@ -197,7 +197,7 @@ public static SelectionPrompt SearchFilter(this SelectionPrompt obj, bo throw new ArgumentNullException(nameof(obj)); } - obj.SearchFilterEnabled = enabled; + obj.SearchEnabled = enabled; return obj; }