Confirmation prompt
IConfirmationPrompt asks a yes/no question. Press y for yes, n for no, Enter for the default. Returns a Boolean.
When to use
- "Continue?" / "Are you sure?" / "Overwrite?" gates.
- Anywhere a one-shot
Booleandecision is needed.
Basic usage
The shortest form:
pascal
if AnsiConsole.Confirm('Proceed?', True) then
RunBuild
else
AnsiConsole.MarkupLine('[yellow]Aborted.[/]');Confirm(prompt, default) returns True for yes, False for no.
Configurable form
For more control, build an IConfirmationPrompt:
pascal
var
prompt : IConfirmationPrompt;
begin
prompt := AnsiConsole.ConfirmationPrompt
.WithTitle('[bold red]Delete files?[/]')
.WithDefault(False)
.WithYesText('delete')
.WithNoText('cancel');
if AnsiConsole.Prompt(prompt) then
DoDelete;
end;Configuration
| Method | Purpose |
|---|---|
WithTitle(value) | Markup title shown above the input. |
WithDefault(value) | Returned when the user presses Enter. |
WithYesText(value) / WithNoText(value) | Override the default y / n labels. |
WithShowDefaultValue(value) | Hide the default-value annotation. |
Cancel handling
Same as text prompts: Esc / Ctrl-C raises EPromptCancelled.
API reference
AnsiConsole.Confirm— convenience.AnsiConsole.ConfirmationPrompt— builder.AnsiConsole.Prompt(confirmationPrompt)— show a configured prompt.IConfirmationPrompt
See also
- Text prompt — for arbitrary string answers.
- Selection prompt — for fixed-choice pickers.