Skip to content

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 Boolean decision 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

MethodPurpose
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

See also

Released under the MIT License.