• Stars
    star
    552
  • Rank 80,595 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interactive command-line based application framework for C#

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

More Repositories

1

keyvault-acmebot

Automated ACME SSL/TLS certificates issuer for Azure Key Vault (App Gateway / Front Door / CDN / others)
C#
683
star
2

appservice-acmebot

Automated ACME SSL/TLS certificates issuer for Azure App Service (Web Apps / Functions / Containers)
C#
368
star
3

WinQuickLook

A lightweight file viewer like "Quick Look" on macOS
C#
307
star
4

ImoutoDesktop

ใ€Œใ„ใ‚‚ใ†ใจใƒ‡ใ‚นใ‚ฏใƒˆใƒƒใƒ—ใ€ใฏใƒ‡ใ‚นใ‚ฏใƒˆใƒƒใƒ—ๅณไธ‹ใซๅธธ้งใ—ใŸๅฆนใ‚ญใƒฃใƒฉใซๆ–‡ๅญ—ๅ…ฅๅŠ›ใงใ•ใพใ–ใพใชใŠ้ก˜ใ„ใ‚’ใ—ใฆใ€ไป– PC ใ‚’ๆ“ไฝœใ—ใฆใ‚‚ใ‚‰ใˆใ‚‹ๅฏพ่ฉฑๅž‹ใฎใƒชใƒขใƒผใƒˆๆ“ไฝœใ‚ฝใƒ•ใƒˆใงใ™ใ€‚
C#
95
star
5

containerapps-acmebot

Automated ACME SSL/TLS certificates issuer for Azure Container Apps
C#
80
star
6

IISManager

IIS Manager Extension for Azure Web Apps
C#
32
star
7

keyvault-certificate-rotation

Automatic updating of the Key Vault Certificate for Azure CDN / Front Door
C#
20
star
8

azure-functions-boilerplate

A boilerplate project for getting started with Azure Functions v4
C#
19
star
9

iislua

It brings the power of Lua scripting in your IIS.
C++
17
star
10

terraform-azurerm-keyvault-acmebot

Terraform Module for Key Vault Acmebot
HCL
16
star
11

SwissKnife

SwissKnife for ASP.NET
C#
16
star
12

CsvHelper.FastDynamic

Fast dynamic CSV records reader and writer extensions for CsvHelper
C#
15
star
13

iisexpress-testkit

IIS Express TestKit
C#
14
star
14

SendGrid.PowerShell

PowerShell Cmdlets for SendGrid
C#
11
star
15

awesome-terraform

Basic Terraform sample definition using Azure and Azure Pipelines.
HCL
10
star
16

IIS.Compression.SiteExtension

IIS.Compression (better gzip and brotli support) for Azure App Service
10
star
17

AppServiceProxy.SiteExtension

Site Extension-based Reverse Proxy compatible with Azure Functions Proxies
C#
9
star
18

azure-functions-http-api

HTTP API Extensions for Azure Functions
C#
9
star
19

iis-http-compression

IIS HTTP Compression Library
C++
8
star
20

SendGridSharp

Simplify SendGrid SMTP / REST v2 API Client for C# / .NET Standard
C#
8
star
21

appserviceinfo

This website to check the platform and runtime information of Azure App Service.
C#
7
star
22

webauthn-aspnet-demo

Demo Application for Windows Hello (Web Authn API)
C#
6
star
23

NuGetMigration

Migrate NuGet package configuration from packages.config to MSBuild (csproj / vbproj)
C#
6
star
24

classic-asp-docker

Docker image for Classic ASP on Windows Server Core
6
star
25

durable-functions-typed-proxy

Type-safe activity helper for Durable Functions
C#
6
star
26

AzureWebSitesSetupScripts

Setup scripts for Azure Web Sites
Batchfile
4
star
27

url-rewrite-visualizer

URL Rewrite Rules Dependency Visualizer
C#
4
star
28

SourceBrowserExtension

SourceBrowser for Azure Site Extension
Batchfile
4
star
29

create-function-app-mock

Sharprompt demo application
C#
4
star
30

MarkovDemo

Markov Chains C# Demo Application
C#
3
star
31

webapp-staticsite-template

Azure Web App Template for Static Site Generator (e.g VuePress, Hugo)
Batchfile
3
star
32

azure-templates

Azure Resource Manager Templates
3
star
33

b2c-graphclient-csharp

A Sample application for Azure AD B2C Graph API
C#
3
star
34

JavaExtension

Java Extension for Azure Web Apps
Batchfile
2
star
35

terraform-azurerm-appservice-acmebot

Terraform Module for App Service Acmebot
HCL
2
star
36

azure-functions-appcenterpush-extension

Azure Functions Bindings for App Center Push
C#
2
star
37

aspnet-mvc5-template

ASP.NET MVC 5 Application Template
C#
2
star
38

azure-jruby-sample

JRuby on Rails application on Azure Web Apps.
Ruby
2
star
39

appveyor-aspnet-docker

HTML
2
star
40

azfunctions-precompiled

Precompiled Azure Function demo repository
Batchfile
2
star
41

OEmbedSharp

C# implementation of oEmbed consumer.
C#
2
star
42

terraform-azurerm-containerapps-acmebot

Terraform Module for Container Apps Acmebot
HCL
2
star
43

JRubyExtension

JRuby Extension for Azure Web Apps
Batchfile
2
star
44

SimpleDiscovery

HttpClientFactory based client service discovery for Azure App Service
C#
2
star
45

sendgrid

Yet Another SendGrid API C# Library
C#
2
star
46

phpMyAdminExtension

phpMyAdmin Extension for Azure Web Apps
PHP
1
star
47

colorsdll

COLORS Imaging Library
C
1
star
48

windows-custom-ami

Shell
1
star
49

durable-entityproxy-proto

C#
1
star
50

beanstalk-to-slack

C#
1
star
51

kudu-nginx-docker

1
star
52

durable-entities-sendgrid-demo

C#
1
star
53

DaruCamera

ใ ใ‚‹ใ‚„ใชใŽใ‚ฏใ‚ฝใ‚ณใƒฉใ‚ซใƒกใƒฉ
C#
1
star
54

WPF-PerMonitorV2-Sample

C#
1
star
55

aspnet-override-config

C#
1
star
56

SitecoreMvcDisplayMode

JavaScript
1
star
57

DaruChoco

ใ ใ‚‹ใ‚„ใชใŽใฎใƒใƒงใ‚ณใƒฌใƒผใƒˆๅคงไฝœๆˆฆ
JavaScript
1
star
58

DaruTweetWin

ใ ใ‚‹ใƒ„ใ‚คใƒผใƒˆAPIใ‚’ๅฉใ„ใฆใ ใ‚‹ใ•ใ‚“ใฎใƒ„ใ‚คใƒผใƒˆใ‚’่กจ็คบใ™ใ‚‹ใƒ‡ใ‚นใ‚ฏใƒˆใƒƒใƒ—ใ‚ขใƒ—ใƒช Win ็‰ˆ
C#
1
star
59

WATableComplexType

C#
1
star
60

MySQLExtension

Local MySQL for Azure Web Apps
Batchfile
1
star
61

RedisCacheClient

RedisCacheClient is a compatible ObjectCache client for .NET Standard
C#
1
star
62

appservice-diagnostic-scripts

Batchfile
1
star