Skip to content

Latest commit

 

History

History
138 lines (95 loc) · 3.47 KB

README.md

File metadata and controls

138 lines (95 loc) · 3.47 KB

Sharprompt

Build License

Interactive command line interface toolkit for .NET Core

sharprompt

NuGet Package

Package Name Target Framework NuGet
Sharprompt .NET Standard 2.0 NuGet

Install

Install-Package Sharprompt
dotnet add package Sharprompt

Features

  • 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)

Usage

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

APIs

Input

var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");

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

Enum value support

var value = Prompt.Select<MyEnum>("Select enum value");
Console.WriteLine($"You selected {value}");

MultiSelect

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

Configuration

Custom Prompter

Prompt.ColorSchema.Answer = ConsoleColor.DarkRed;
Prompt.ColorSchema.Select = ConsoleColor.DarkCyan;

var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");

Unicode Support

unicode

// Prefer UTF-8 as the output encoding
Console.OutputEncoding = Encoding.UTF8;

var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");

Platforms

  • Windows
    • Cmd / PowerShell / Windows Terminal
  • Ubuntu
    • Bash
  • macOS
    • Bash

License

This project is licensed under the MIT License