Sharprompt 3.0.0-preview4
This is a prerelease version of Sharprompt.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Sharprompt --version 3.0.0-preview4
NuGet\Install-Package Sharprompt -Version 3.0.0-preview4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sharprompt" Version="3.0.0-preview4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sharprompt --version 3.0.0-preview4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Sharprompt, 3.0.0-preview4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sharprompt as a Cake Addin #addin nuget:?package=Sharprompt&version=3.0.0-preview4&prerelease // Install Sharprompt as a Cake Tool #tool nuget:?package=Sharprompt&version=3.0.0-preview4&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Sharprompt
Interactive command-line based application framework for C#
Features
- Multi-platform support
- Supports the popular prompts (
Input
/Password
/Select
/ etc) - Supports model-based prompts
- Validation of input value
- Automatic generation of data source using Enum type
- Customizable symbols and color schema
- Unicode support (Multi-byte characters and Emoji😀🎉)
Installation
Install-Package Sharprompt
dotnet add package Sharprompt
// Simple input
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
// Password input
var secret = Prompt.Password("Type new password", validators: new[] { Validators.Required(), Validators.MinLength(8) });
Console.WriteLine("Password OK");
// Confirmation
var answer = Prompt.Confirm("Are you ready?", defaultValue: true);
Console.WriteLine($"Your answer is {answer}");
Examples
The project in the folder Sharprompt.Example
contains all the samples. Please check it.
dotnet run --project Sharprompt.Example
Prompt types
Input
Takes a generic type parameter and performs type conversion as appropriate.
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
var number = Prompt.Input<int>("Enter any number");
Console.WriteLine($"Input = {number}");
Confirm
var answer = Prompt.Confirm("Are you ready?");
Console.WriteLine($"Your answer is {answer}");
Password
var secret = Prompt.Password("Type new password");
Console.WriteLine("Password OK");
Select
var city = Prompt.Select("Select your city", new[] { "Seattle", "London", "Tokyo" });
Console.WriteLine($"Hello, {city}!");
MultiSelect (Checkbox)
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(", ", cities)}");
List
var value = Prompt.List<string>("Please add item(s)");
Console.WriteLine($"You picked {string.Join(", ", value)}");
Bind (Model-based prompts)
// Input model definition
public class MyFormModel
{
[Display(Name = "What's your name?")]
[Required]
public string Name { get; set; }
[Display(Name = "Type new password")]
[DataType(DataType.Password)]
[Required]
[MinLength(8)]
public string Password { get; set; }
[Display(Name = "Select your city")]
[Required]
[InlineItems("Seattle", "London", "Tokyo")]
public string City { get; set; }
[Display(Name = "Are you ready?")]
public bool? Ready { get; set; }
}
var result = Prompt.Bind<MyFormModel>();
Configuration
Symbols
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}!");
Color schema
Prompt.ColorSchema.Answer = ConsoleColor.DarkRed;
Prompt.ColorSchema.Select = ConsoleColor.DarkCyan;
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
Cancellation support
// 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");
}
Features
Enum type support
public enum MyEnum
{
[Display(Name = "First value")]
First,
[Display(Name = "Second value")]
Second,
[Display(Name = "Third value")]
Third
}
var value = Prompt.Select<MyEnum>("Select enum value");
Console.WriteLine($"You selected {value}");
Unicode support
// Prefer UTF-8 as the output encoding
Console.OutputEncoding = Encoding.UTF8;
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
Fluent interface support
using Sharprompt.Fluent;
// Use fluent interface
var city = Prompt.Select<string>(o => o.WithMessage("Select your city")
.WithItems(new[] { "Seattle", "London", "Tokyo" })
.WithDefaultValue("Seattle"));
Supported platforms
- Windows
- Command Prompt
- PowerShell
- Windows Terminal
- Linux (Ubuntu, etc)
- Windows Terminal (WSL 2)
- macOS
- Terminal.app
License
This project is licensed under the MIT License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Sharprompt:
Package | Downloads |
---|---|
NukeBuildHelpers
NukeBuildHelpers for Nuke build. |
|
Dabit.Utils.YamlConfigManager
Package Description |
|
NiuX
NiuX 基础设施 |
|
Filepicker
Simple CLI UI filepicker with directory navigation |
|
42.CLI.Toolkit
Handy toolkit for a fancy CLI application. |
GitHub repositories (10)
Showing the top 5 popular GitHub repositories that depend on Sharprompt:
Repository | Stars |
---|---|
AutoDarkMode/Windows-Auto-Night-Mode
Automatically switches between the dark and light theme of Windows 10 and Windows 11
|
|
github/gh-actions-importer
GitHub Actions Importer helps you plan and automate the migration of Azure DevOps, Bamboo, Bitbucket, CircleCI, GitLab, Jenkins, and Travis CI pipelines to GitHub Actions.
|
|
github/gh-valet
Valet helps facilitate the migration of Azure DevOps, CircleCI, GitLab CI, Jenkins, and Travis CI pipelines to GitHub Actions.
|
|
microsoft/winget-create
The Windows Package Manager Manifest Creator command-line tool (aka wingetcreate)
|
|
void-stack/VMUnprotect.Dumper
VMUnprotect.Dumper can dynamically untamper VMProtected Assembly.
|
Version | Downloads | Last updated |
---|---|---|
3.0.0-preview5 | 70 | 11/16/2024 |
3.0.0-preview4 | 3,680 | 9/4/2023 |
3.0.0-preview3 | 630 | 8/12/2023 |
3.0.0-preview2 | 6,850 | 11/29/2022 |
3.0.0-preview1 | 642 | 11/13/2022 |
2.4.5 | 397,050 | 9/27/2022 |
2.4.4 | 10,144 | 8/26/2022 |
2.4.3 | 16,047 | 7/13/2022 |
2.4.2 | 3,830 | 7/6/2022 |
2.4.1 | 30,762 | 4/4/2022 |
2.4.0 | 18,840 | 12/31/2021 |
2.4.0-preview3 | 739 | 12/13/2021 |
2.4.0-preview2 | 670 | 12/10/2021 |
2.4.0-preview1 | 769 | 11/14/2021 |
2.3.7 | 15,634 | 11/6/2021 |
2.3.6 | 1,140 | 10/17/2021 |
2.3.5 | 1,787 | 10/1/2021 |
2.3.4 | 1,561 | 9/20/2021 |
2.3.3 | 6,628 | 8/16/2021 |
2.3.2 | 1,985 | 8/5/2021 |
2.3.1 | 2,140 | 8/1/2021 |
2.3.0 | 1,031 | 7/26/2021 |
2.3.0-preview3 | 760 | 7/24/2021 |
2.3.0-preview2 | 748 | 7/14/2021 |
2.3.0-preview1 | 760 | 6/18/2021 |
2.2.1 | 41,685 | 4/29/2021 |
2.2.0 | 1,781 | 4/19/2021 |
2.2.0-preview2 | 834 | 3/5/2021 |
2.2.0-preview1 | 764 | 2/20/2021 |
2.1.2 | 8,454 | 1/27/2021 |
2.1.1 | 1,000 | 1/20/2021 |
2.1.0 | 1,614 | 12/31/2020 |
2.1.0-preview3 | 844 | 12/9/2020 |
2.1.0-preview2 | 834 | 11/27/2020 |
2.1.0-preview1 | 964 | 10/14/2020 |
2.0.0 | 13,486 | 8/13/2020 |
2.0.0-preview5 | 861 | 8/10/2020 |
2.0.0-preview4 | 928 | 8/2/2020 |
2.0.0-preview3 | 919 | 6/26/2020 |
2.0.0-preview2 | 964 | 6/8/2020 |
2.0.0-preview1 | 922 | 6/7/2020 |
1.0.5 | 1,783 | 5/6/2020 |
1.0.4 | 3,571 | 2/17/2020 |
1.0.3 | 11,210 | 10/31/2019 |
1.0.2 | 1,169 | 8/31/2019 |
1.0.1 | 1,146 | 8/10/2019 |
1.0.0 | 1,592 | 8/9/2019 |
1.0.0-preview3 | 976 | 8/2/2019 |
1.0.0-preview2 | 955 | 8/2/2019 |
1.0.0-preview | 956 | 7/31/2019 |