RankedListPrompt<T> class
RankedListPrompt – composable system for searchable lists with custom ranking.
Extends the search pattern with:
- Custom ranking/scoring for each item
- Match highlight spans for visual feedback
- Fuzzy or substring matching modes
Design principles:
- Composition over inheritance
- Separation of concerns (ranking is separate from navigation/rendering)
- DRY: Centralizes the ranked search pattern (CommandPalette, etc.)
Usage:
final prompt = RankedListPrompt<CommandEntry>(
title: 'Command Palette',
items: commands,
rankItem: (item, query, useFuzzy) => fuzzyMatch(item.title, query),
itemLabel: (item) => item.title,
);
final result = prompt.run();
Constructors
-
RankedListPrompt({required String title, required List<
T> items, PromptTheme theme = PromptTheme.dark, int maxVisible = 12, bool alwaysShowSearch = true, bool initialFuzzyMode = true, int reservedLines = 8})
Properties
- alwaysShowSearch → bool
-
Whether search input is always visible (vs toggle with /).
final
- bindings → KeyBindings
-
Current key bindings.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialFuzzyMode → bool
-
Initial search mode (true = fuzzy, false = substring).
final
-
items
→ List<
T> -
All items (before ranking).
final
- maxVisible → int
-
Maximum visible items (viewport size).
final
-
Current navigation state.
no setter
- queryInput → TextInputBuffer
-
Current search query input.
no setter
-
ranked
→ List<
RankedItem< T> > -
Currently ranked items.
no setter
- reservedLines → int
-
Terminal lines to reserve for chrome.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- theme → PromptTheme
-
Theme for styling.
final
- title → String
-
Title for the frame header.
final
- useFuzzy → bool
-
Whether fuzzy mode is active.
no setter
- wasCancelled → bool
-
Whether the prompt was cancelled.
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
run(
{required RankResult? rankItem(T item, String query, bool useFuzzy), required String itemLabel(T item), String? itemSubtitle(T item)?, void renderItem(FrameContext ctx, RankedItem< T> rankedItem, int index, bool isFocused, String query)?, void beforeItems(FrameContext ctx, String query, bool useFuzzy, int matchCount)?, KeyBindings? extraBindings}) → T? - Runs the ranked list prompt.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited