GithubHelp home page GithubHelp logo

lonelyevil / sharprompt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shibayan/sharprompt

0.0 1.0 0.0 107 KB

Interactive command line interface toolkit for .NET Core

License: MIT License

C# 100.00%

sharprompt's Introduction

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

sharprompt's People

Contributors

0xflotus avatar m-nab avatar shibayan avatar wischi-chr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.