Interactive command line interface toolkit for .NET Core
Package Name | Target Framework | NuGet |
---|---|---|
Sharprompt | .NET Standard 2.0 |
Install-Package Sharprompt
dotnet add package Sharprompt
- Multi-platform support
- Supports the popular Prompts (Input / Password / Select / etc)
- Validation of input value
- Automatic generation of data source using Enum value
- Customize the color scheme
- Unicode support (East asian width and Emoji)
// 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 value 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)}");
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}!");
- Windows
- Cmd / PowerShell / Windows Terminal
- Ubuntu
- Bash
- macOS
- Bash
This project is licensed under the MIT License