Sharprompt 2.4.1

.NET Standard 2.0
Install-Package Sharprompt -Version 2.4.1
dotnet add package Sharprompt --version 2.4.1
<PackageReference Include="Sharprompt" Version="2.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sharprompt --version 2.4.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Sharprompt, 2.4.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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=2.4.1

// Install Sharprompt as a Cake Tool
#tool nuget:?package=Sharprompt&version=2.4.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Sharprompt

Build Downloads NuGet License

Interactive command-line based application framework for C#

sharprompt

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}");

input

Confirm

var answer = Prompt.Confirm("Are you ready?");
Console.WriteLine($"Your answer is {answer}");

confirm

Password

var secret = Prompt.Password("Type new password");
Console.WriteLine("Password OK");

password

Select

var city = Prompt.Select("Select your city", new[] { "Seattle", "London", "Tokyo" });
Console.WriteLine($"Hello, {city}!");

select

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)}");

multiselect

List

var value = Prompt.List<string>("Please add item(s)");
Console.WriteLine($"You picked {string.Join(", ", value)}");

list

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}!");

unicode support

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
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Sharprompt:

Package Downloads
Dabit.Utils.YamlConfigManager

Package Description

NiuX

NiuX 基础设施

Filepicker

Simple CLI UI filepicker with directory navigation

GitHub repositories (4)

Showing the top 4 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
OpenTouryoProject/OpenTouryo
”Open棟梁”は、長年の.NETアプリケーション開発実績にて蓄積したノウハウに基づき開発した.NET用アプリケーション フレームワークです。 (”OpenTouryo” , is an application framework for .NET which was developed using the accumulated know-how with a long track record in .NET application development.)
Maoni0/realmon
A monitoring tool that tells you when GCs happen in a process and some characteristics about these GCs
microsoft/winget-create
The Windows Package Manager Manifest Creator command-line tool (aka wingetcreate)
Version Downloads Last updated
2.4.1 4,069 4/4/2022
2.4.0 13,826 12/31/2021
2.4.0-preview3 114 12/13/2021
2.4.0-preview2 71 12/10/2021
2.4.0-preview1 178 11/14/2021
2.3.7 7,273 11/6/2021
2.3.6 427 10/17/2021
2.3.5 863 10/1/2021
2.3.4 684 9/20/2021
2.3.3 4,388 8/16/2021
2.3.2 452 8/5/2021
2.3.1 908 8/1/2021
2.3.0 242 7/26/2021
2.3.0-preview3 131 7/24/2021
2.3.0-preview2 154 7/14/2021
2.3.0-preview1 150 6/18/2021
2.2.1 17,079 4/29/2021
2.2.0 1,084 4/19/2021
2.2.0-preview2 129 3/5/2021
2.2.0-preview1 120 2/20/2021
2.1.2 5,447 1/27/2021
2.1.1 274 1/20/2021
2.1.0 819 12/31/2020
2.1.0-preview3 189 12/9/2020
2.1.0-preview2 178 11/27/2020
2.1.0-preview1 323 10/14/2020
2.0.0 7,066 8/13/2020
2.0.0-preview5 214 8/10/2020
2.0.0-preview4 296 8/2/2020
2.0.0-preview3 268 6/26/2020
2.0.0-preview2 294 6/8/2020
2.0.0-preview1 286 6/7/2020
1.0.5 916 5/6/2020
1.0.4 2,348 2/17/2020
1.0.3 696 10/31/2019
1.0.2 390 8/31/2019
1.0.1 399 8/10/2019
1.0.0 325 8/9/2019
1.0.0-preview3 310 8/2/2019
1.0.0-preview2 304 8/2/2019
1.0.0-preview 290 7/31/2019