Interactive command-line based application framework for C#
$ dotnet add package SharpromptInteractive command-line based application framework for C#

Install-Package Sharprompt
dotnet add package Sharprompt
Input / Password / Select / etc)// Simple input prompt
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
// Password prompt
var secret = Prompt.Password("Type new password", new[] { Validators.Required(), Validators.MinLength(8) });
Console.WriteLine("Password OK");
// Confirmation prompt
var answer = Prompt.Confirm("Are you ready?", defaultValue: true);
Console.WriteLine($"Your answer is {answer}");
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
var answer = Prompt.Confirm("Are you ready?");
Console.WriteLine($"Your answer is {answer}");
var secret = Prompt.Password("Type new password");
Console.WriteLine("Password OK");
var city = Prompt.Select("Select your city", new[] { "Seattle", "London", "Tokyo" });
Console.WriteLine($"Hello, {city}!");
Enum support
var value = Prompt.Select<MyEnum>("Select enum value");
Console.WriteLine($"You selected {value}");var cities = Prompt.MultiSelect("Which cities would you like to visit?", new[] { "Seattle", "London", "Tokyo", "New York", "Singapore", "Shanghai" }, pageSize: 3);
Console.WriteLine($"You picked {string.Join(", ", options)}");
var value = Prompt.List<string>("Please add item(s)");
Console.WriteLine($"You picked {string.Join(", ", value)}");
// Model definition
public class MyFormModel
{
[Display(Prompt = "What's your name?")]
[Required]
public string Name { get; set; }
[Display(Prompt = "Type new password")]
[DataType(DataType.Password)]
[Required]
[MinLength(8)]
public string Password { get; set; }
[Display(Prompt = "Are you ready?")]
public bool Ready { get; set; }
}
var result = Prompt.AutoForms<MyFormModel>();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?");
Console.WriteLine($"Hello, {name}!");Prompt.ColorSchema.Answer = ConsoleColor.DarkRed;
Prompt.ColorSchema.Select = ConsoleColor.DarkCyan;
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");// Prefer UTF-8 as the output encoding
Console.OutputEncoding = Encoding.UTF8;
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
// Throw an exception when canceling with Ctrl-C
Prompt.ThrowExceptionOnCancel = true;
try
{
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
}
catch (PromptCanceledException ex)
{
Console.WriteLine("Prompt canceled");
}This project is licensed under the MIT License