search<T> static method
T
search<T>(})
Lets the user pick one of options by typing to filter them, like a
command palette.
Matching is fuzzy (see Fuzzy): gco finds git checkout. The best
matches come first, with the matched letters underlined. note text is
searched too, so it suits descriptions.
final command = Prompts.search(
'Run',
commands,
format: (c) => c.name,
note: (c) => c.description,
);
Implementation
static T search<T>(
String prompt,
List<T> options, {
String Function(T option)? format,
String Function(T option)? note,
T? defaultOption,
int? pageSize,
}) {
final start = defaultOption == null ? -1 : options.indexOf(defaultOption);
return PromptRunner.run(
SearchPrompt<T>(
prompt,
options,
format: format,
note: note,
defaultIndex: start < 0 ? null : start,
pageSize: pageSize,
),
);
}