A collection of common interactive command line user interfaces.
Clone of Inquirer.js
Install-Package Inquirer.cs
List<ConsoleColor> colors = Enum.GetValues(typeof(ConsoleColor)).Cast<ConsoleColor>().ToList();
Question.List("Choose favourite color", colors);
List<ConsoleColor> colors = Enum.GetValues(typeof(ConsoleColor)).Cast<ConsoleColor>().ToList();
Question.RawList("Choose favourite color", colors);
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);
var colors = Enum.GetValues(typeof(ConsoleColor)).Cast<ConsoleColor>().ToList();
Question.Checkbox("Choose favourite colors", colors);
Question.Confirm("Are you sure?");
Question.Input("How are you?");
Question.Input<int>("2+2")
Question.Password("Type password");
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();
}
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)
_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();