PromptPlus

PromptPlus # PromptPlus ## **Confirm — Operations** [![NuGet](https://img.shields.io/badge/NuGet-PromptPlus-blue)](https://www.nuget.org/packages/PromptPlus) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![.NET](https://img.shields.io/badge/.NET-8%20%7C%209%20%7C%2010-512BD4)](https://dotnet.microsoft.com/)

← Back to HomeNext: Confirm — Styles →


Confirm runs on the same engine as KeyPress, so its runtime behavior — the single-keystroke wait, valid-key matching, invalid-key message, tooltip, and abort — is exactly the same. This page notes only what is specific to the yes/no preset and links to the shared reference on KeyPress → Operations.


Anatomy of the control

Apply changes? (Y/N)                     ← prompt — Confirm always appends " (Yes/No key)" itself
Press the culture-specific Yes/No key    ← description (optional)
Esc:Abort.Ctrl+F1:Show/hide tooltip      ← tooltip — does NOT list the valid Y/N keys, only hints

Every region can be recolored — see Styles.


What Confirm pre-registers

Confirm calls the KeyPress engine with the current culture’s Yes and No keys already registered as valid keys. Consequences:

You can still register extra keys with AddValidKey; they are accepted in addition to Yes/No.


The shared behaviors

Everything below works identically to KeyPress — follow the links for the details:

Behavior Reference
Single-keystroke wait (returns on the first accepted key) KeyPress → Single-keystroke wait
Valid-key restriction (accumulates; Yes/No are pre-set here) KeyPress → Valid-key restriction
Invalid-key message KeyPress → Invalid-key message
Tooltip (F1 / Ctrl+F1) KeyPress → Tooltip
Abort (Esc → .IsAborted, no .Content value) KeyPress → Abort
Options overrides KeyPress → Options that change behavior

Interpreting yes vs. no

The result is a ConsoleKeyInfo?, not a bool. Compare the pressed character to the Yes char:

var confirm = PromptPlus.Controls.Confirm("Continue?").Run();

if (!confirm.IsAborted &&
    confirm.Content is { } k &&
    char.ToUpperInvariant(k.KeyChar) == char.ToUpperInvariant(PromptPlus.Config.YesChar))
{
    // Yes
}

Branch on .IsAborted first — an aborted confirm carries no .Content value and is neither yes nor no.


See also