Skip to content

Configuration

Sharprompt allows you to customize the appearance and behavior of prompts globally.

Symbols

You can customize the symbols used by prompts:

csharp
Prompt.Symbols.Prompt = new Symbol("🤔", "?");
Prompt.Symbols.Done = new Symbol("😎", "V");
Prompt.Symbols.Error = new Symbol("😱", ">>");

var name = Prompt.Input<string>("What's your name?");

The Symbol class takes two arguments: a Unicode value and a fallback value for terminals that don't support Unicode.

Available Symbols

SymbolDefault (Unicode)Default (Fallback)Description
Prompt??Displayed before the prompt message
DoneVDisplayed when the prompt is completed
Error»>>Displayed when validation fails
Selector>Points to the currently highlighted item
Selected(*)Marks a selected item in MultiSelect
NotSelect( )Marks an unselected item in MultiSelect

Color Schema

Customize the colors used by prompts:

csharp
Prompt.ColorSchema.Answer = ConsoleColor.DarkRed;
Prompt.ColorSchema.Select = ConsoleColor.DarkCyan;

var name = Prompt.Input<string>("What's your name?");

Available Colors

PropertyDefaultDescription
DoneSymbolGreenColor of the done symbol
PromptSymbolGreenColor of the prompt symbol
AnswerCyanColor of the user's answer
SelectGreenColor of the selected item
ErrorRedColor of error messages
HintDarkGrayColor of hints and placeholders
DisabledOptionDarkCyanColor of disabled options

Cancellation Support

By default, pressing Ctrl+C returns the default value. You can change this behavior to throw an exception:

csharp
Prompt.ThrowExceptionOnCancel = true;

try
{
    var name = Prompt.Input<string>("What's your name?");
    Console.WriteLine($"Hello, {name}!");
}
catch (PromptCanceledException ex)
{
    Console.WriteLine("Prompt canceled");
}

Culture

Set the culture for localized messages:

csharp
Prompt.Culture = new CultureInfo("ja");

Console Driver

You can provide a custom console driver factory:

csharp
Prompt.ConsoleDriverFactory = () => new MyCustomConsoleDriver();

Released under the MIT License.