PromptPlus

PromptPlus # PromptPlus ## **Input** [![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 — Methods →


Single-line, free-text entry. The user types plain text and confirms with Enter.

The Input control is the workhorse for collecting any unstructured string — a name, an e-mail address, a URL, a search term, a note. It supports live character filtering, case coercion, length limits, confirmation-time validation, Tab autocomplete suggestions, and persistent history — all through a single fluent chain.

🔒 Need to hide what the user types (passwords, API keys, PINs)? Use the Secret control instead. It’s related, not identical: Secret adds the mask character but deliberately drops Default/DefaultIfEmpty, EnableHistory, and both suggestion methods — a secret shouldn’t be pre-seeded, persisted, or suggested.


On this page

Sub-page What you will find
Index (this page) What it is, when to use it, a first working example, the method map
Methods Every fluent method — signature, parameters, defaults, and a snippet
Operations Keyboard, validation flow, history, autocomplete, and edge cases
Styles The InputStyles regions and how to recolor them

When to use it

Use Input when… Consider instead…
You need any free-form string
The value is a password or secret Secret
The value must match a fixed pattern (date, phone, currency) MaskEdit
The user should pick from a known list Select

Minimal example

using PromptPlusLibrary;

var result = PromptPlus.Controls
    .Input("Your name")
    .Run();

if (!result.IsAborted)
    PromptPlus.Console.WriteLine($"Hello, {result.Content}!");

⚠️ Always check IsAborted before using .Content. On abort, .Content is not guaranteed to be empty — it holds whatever is currently in the buffer (a seeded Default the user never typed over, or partially-typed text).


A more complete example

using PromptPlusLibrary;

var pin = PromptPlus.Controls
    .Input("PIN", "Only digits are accepted (max 5)")
    .AcceptInput(char.IsDigit)          // reject any non-digit keystroke
    .MaxLength(5)                        // stop accepting after 5 characters
    .PredicateValid(v => v.Length == 5
        ? (true, null)
        : (false, "PIN must be exactly 5 digits"))   // validate on Enter
    .Run();

if (!pin.IsAborted)
    PromptPlus.Console.WriteLine($"PIN accepted.");

This shows the three most common building blocks together: per-keystroke filtering (AcceptInput), a hard length cap (MaxLength), and confirmation-time validation with a message (PredicateValid). See Operations for how they interact.


Method map

Grouped by purpose. Full signatures and examples are on the Methods page.

Purpose Methods
Seed a value Default, DefaultIfEmpty
Restrict typing AcceptInput, MaxLength, InputToCase
Validate on confirm PredicateValid, PredicateValidAsync
Autocomplete SuggestionHandler, SuggestionHandlerAsync, MinimumSuggestionLength
History EnableHistory
Dynamic description ChangeDescription, ChangeDescriptionAsync
Appearance & behavior Styles, Options
Run Run

Return value

Input returns ResultPrompt<string>.

Member Meaning
.Content The confirmed text — or whatever is in the buffer at the moment of an abort, not necessarily empty
.IsAborted true when the user pressed Esc / the abort key
var (text, aborted) = PromptPlus.Controls.Input("Name").Run();
if (!aborted) PromptPlus.Console.WriteLine(text);

See also