Skip to content

Latest commit

 

History

History
97 lines (68 loc) · 3.95 KB

operations.md

File metadata and controls

97 lines (68 loc) · 3.95 KB
PromptPlus

PromptPlus

Confirm — Operations

NuGet License: MIT .NET

← Back to Home • Next: 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:

  • Only the Yes key and the No key end the wait; any other key is rejected (and shows the invalid-key message if one is configured).
  • The specific letters depend on the active culture. In en-US they are Y/N; switching PromptPlus.Config.DefaultCulture to, say, pt-BR switches them to that culture's letters.
  • PromptPlus.Config.YesChar / NoChar expose the active pair, which is how you interpret the result (see Index).
  • Confirm(...) automatically appends " ({yesKey}/{noKey})" to whatever prompt text you pass — e.g. Confirm("Apply changes?") renders as Apply changes? (Y/N). You don't need to (and shouldn't) add this hint yourself.

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