PromptPlus

PromptPlus # PromptPlus ## **Input — 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: Input — Styles →


How the Input control behaves while it is running: keyboard, the order in which restrictions and validation apply, history, autocomplete, and the small details that matter in real apps.


Anatomy of the control

Name: John_                              ← prompt + typed text + cursor
First and last name                      ← description (optional / dynamic)
Current length: 4                        ← ChangeDescription output (optional)
Value is invalid                         ← error line, only when validation fails
Enter: confirm  Esc: cancel  F3: history ← tooltip (toggle with F1 / Ctrl+F1)

Every region can be recolored — see Styles.


Keyboard

Editing

Key Action
Any printable character Insert at the cursor (subject to AcceptInput and MaxLength)
/ Move one character
Home / End Start / end of line
Backspace Delete character before the cursor
Delete Delete character at the cursor
Insert Toggle insert / overwrite mode

There is no plain (non-Emacs) word-motion or word-deletion binding: Ctrl+←/Ctrl+→, Ctrl+Backspace, and Ctrl+Delete do not move/delete by word. Word motion/deletion is Emacs-only — Alt+F/Alt+B to move, Ctrl+W/Alt+D to delete — see the warning below.

Actions

Key Action
Enter Confirm — runs validation, then returns the value
Esc Abort (when the abort key is enabled) → IsAborted == true
Tab / Shift+Tab Autocomplete — behavior differs by mode, see Autocomplete below
F3 Open history navigation (when history is enabled)
F1 Cycle tooltip content
Ctrl+F1 Show / hide the tooltip

When Emacs key bindings are enabled (PromptPlus.Console.EnabledEmacs = true), the text also responds to Ctrl+A/E/B/F/D/K/U/W/T and friends (no Ctrl+Y — there’s no yank/kill-buffer support here). See Keyboard Bindings for the full table.


How a keystroke is processed

The restrictions apply in a fixed order, so it helps to picture the pipeline:

key pressed
   │
   ├─ is it a control/navigation key? --→ handled (move, delete, confirm, …)
   │
   └─ printable character
          │
          ├─ InputToCase applied FIRST (upper/lower) — before AcceptInput ever sees the char
          ├─ AcceptInput(transformedChar) == false? --→ ignored
          ├─ length already == MaxLength? --→ ignored
          └─ inserted at cursor

Consequently:


Confirmation & validation flow

Pressing Enter runs this sequence:

  1. Validation runs — PredicateValid / PredicateValidAsync, if configured — against the raw typed value, even if it’s empty.
  2. Invalid → the control stays open, shows the error line, and waits for more input. Valid → only now, if the field was empty, DefaultIfEmpty’s value is substituted; the control closes and returns ResultPrompt<string> with IsAborted == false.

⚠️ DefaultIfEmpty runs AFTER validation, not before. A PredicateValid that rejects empty input will reject an empty field before DefaultIfEmpty ever gets a chance to substitute its value — the substitution only happens once the raw (possibly empty) value has already passed validation. If you want an empty field to be valid, your predicate must accept empty strings.

⚠️ Validation only runs on confirm, never per keystroke. Use AcceptInput for per-keystroke rules and PredicateValid for whole-value rules (length, format, uniqueness).


History

When EnableHistory(filename, …) is set:

⚠️ Ctrl+Delete, while the history list is open, deletes the entire on-disk history file — not a single entry, the whole store. This is a real, destructive, and easy-to-trigger-by-accident action (it’s the same physical key combo a user might reach for expecting “delete word”).

You can also manage a history store directly with PromptPlus.Controls.History(filename) — add, save, or remove entries programmatically (used in the samples to seed reproducible data).

⚠️ Do not enable history on secret fields — confirmed values are written to disk in the store.


Autocomplete

When a suggestion handler is set, the provider is called once the typed length reaches MinimumSuggestionLength. What happens next depends on autocomplete, and the two modes behave quite differently — this isn’t just “same feature, different key”:

History (F3) and suggestions (Tab) are independent features and can be used together.


Options that change behavior

Set per instance via Options(...), or globally on PromptPlus.Config:

Option Effect on Input
EnabledAbortKey(false) Removes Esc — the user must confirm
HideAfterFinish(true) Erases the field after confirm — the whole control is erased, not just the interactive part
HideOnAbort(true) Erases the field after Esc
ShowTooltip(false) Hides the keyboard hint line
Prompt(...) / Description(...) Overrides the prompt / description text

Edge cases & gotchas


See also