Skip to content

A collection of common interactive command line user interfaces. Port of Inquirer.js

License

Notifications You must be signed in to change notification settings

willsmith9182/Inquirer.cs

 
 

Repository files navigation

Inquirer.cs

A collection of common interactive command line user interfaces.

Clone of Inquirer.js

Installation

Install-Package Inquirer.cs

Prompt types

List

List<ConsoleColor> colors = Enum.GetValues(typeof(ConsoleColor)).Cast<ConsoleColor>().ToList();
Question.List("Choose favourite color", colors);

Raw List

List<ConsoleColor> colors = Enum.GetValues(typeof(ConsoleColor)).Cast<ConsoleColor>().ToList();
Question.RawList("Choose favourite color", colors);

Expand

var colors = new Dictionary<ConsoleKey, ConsoleColor>();
            colors.Add(ConsoleKey.B, ConsoleColor.Blue);
            colors.Add(ConsoleKey.C, ConsoleColor.Cyan);
            colors.Add(ConsoleKey.D, ConsoleColor.DarkBlue);

Question.ExtendedList("Choose favourite color", colors);

Checkbox

var colors = Enum.GetValues(typeof(ConsoleColor)).Cast<ConsoleColor>().ToList();
Question.Checkbox("Choose favourite colors", colors);

Confirm

Question.Confirm("Are you sure?");

Input

Question.Input("How are you?");
Question.Input<int>("2+2")

Password

Question.Password("Type password");

Menu

private static void MenuTest()
        {
            Question.Menu("Choose")
               .AddOption("PagingCheckboxTest", () => { PagingCheckboxTest(); })
               .AddOption("PagingRawListTest", () => { PagingRawListTest(); })
               .AddOption("PagingListTest", () => { PagingListTest(); })
               .AddOption("InputTest", () => { InputTest(); })
               .AddOption("PasswordTest", () => { PasswordTest(); })
               .AddOption("ListTest", () => { ListTest(); })
               .AddOption("ListRawTest", () => { ListRawTest(); })
               .AddOption("ListCheckboxTest", () => { ListCheckboxTest(); })
               .AddOption("ListExtendedTest", () => { ListExtendedTest(); })
               .AddOption("ConfirmTest", () => { ConfirmTest(); }).Prompt();
        }

Extensions

Change the number of lines that will be rendered when using list, rawList, or checkbox.

.Page(int pageSize)

Default value(s) to use if nothing is entered.

.WithDefaultValue(...)
args:
TResult defaultValue
List<TResult> defaultValues : for list types and types implementing IComparable
Func<TResult, bool> compareTo : for list types not implementing IComparable

Chosen value displayed for final confirmation

For password type, user have to confirm password by typing it again

.WithConfirmation()

Set display name for complex type

.WithConvertToString(Func<TResult, string> fn)

Should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.

.WithValidation(Func<TResult, bool> fn, string errorMessage)
.WithValidation(Func<TResult, bool> fn, Func<TResult, string> errorMessageFn)

Inquirer

_test = new Inquirer();

Inquirer is for preserving history It supports

  • navigation
  • optional prompts
  • hierarchical prompts
string answer = string.Empty;
Inquirer.Prompt(Question.Input("1")).Bind(() => answer);
Inquirer.Prompt(Question.Input("2")).Bind(() => answer);
Inquirer.Prompt(() =>
{
    if (answer.Length > 5)
    {
        return Question.Input("3");
    }

    return null;
}).Then(answer2 =>
{
    Inquirer.Prompt(Question.Input("3.1")).Bind(() => answer);
    Inquirer.Prompt(Question.Input("3.2")).Bind(() => answer);
    Inquirer.Prompt(Question.Input("3.3")).Bind(() => answer);
});
Inquirer.Go();

About

A collection of common interactive command line user interfaces. Port of Inquirer.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%