Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/agolaszewski/inquirer.cs
A collection of common interactive command line user interfaces. Port of Inquirer.js
https://github.com/agolaszewski/inquirer.cs
command-line console csharp dot-net dotnet prompt
Last synced: about 2 months ago
JSON representation
A collection of common interactive command line user interfaces. Port of Inquirer.js
- Host: GitHub
- URL: https://github.com/agolaszewski/inquirer.cs
- Owner: agolaszewski
- License: gpl-3.0
- Archived: true
- Created: 2017-08-28T20:55:33.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-06T12:20:33.000Z (over 3 years ago)
- Last Synced: 2024-09-28T22:25:05.035Z (about 2 months ago)
- Topics: command-line, console, csharp, dot-net, dotnet, prompt
- Language: C#
- Homepage:
- Size: 2.01 MB
- Stars: 28
- Watchers: 2
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[build]: https://ci.appveyor.com/project/agolaszewski/inquirer-cs
[build-img]: https://img.shields.io/appveyor/ci/agolaszewski/inquirer-cs.svg
[nuget-img]: https://img.shields.io/nuget/v/Inquirer.cs.svg
[nuget]: https://www.nuget.org/packages/Inquirer.cs/[checkbox-img]: Assets/Screenshots/checkbox.png
[confirm-img]: Assets/Screenshots/confirm.PNG
[extended-img]: Assets/Screenshots/extended.png
[input-img]: Assets/Screenshots/input.png
[list-img]: Assets/Screenshots/list.png
[password-img]: Assets/Screenshots/password.PNG
[rawlist-img]: Assets/Screenshots/rawlist.pngInquirer.cs
===========[![][build-img]][build]
[![][nuget-img]][nuget]A collection of common interactive command line user interfaces.
Clone of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js)
## Installation
```shell
Install-Package Inquirer.cs
```## Prompt types
#### List
```csharp
List colors = Enum.GetValues(typeof(ConsoleColor)).Cast().ToList();
Question.List("Choose favourite color", colors);
```
![][list-img]#### Raw List
```csharp
List colors = Enum.GetValues(typeof(ConsoleColor)).Cast().ToList();
Question.RawList("Choose favourite color", colors);
```
![][rawlist-img]#### Expand
```csharp
var colors = new Dictionary();
colors.Add(ConsoleKey.B, ConsoleColor.Blue);
colors.Add(ConsoleKey.C, ConsoleColor.Cyan);
colors.Add(ConsoleKey.D, ConsoleColor.DarkBlue);Question.ExtendedList("Choose favourite color", colors);
```
![][extended-img]#### Checkbox
```csharp
var colors = Enum.GetValues(typeof(ConsoleColor)).Cast().ToList();
Question.Checkbox("Choose favourite colors", colors);
```
![][checkbox-img]#### Confirm
```csharp
Question.Confirm("Are you sure?");
```
![][confirm-img]#### Input
```csharp
Question.Input("How are you?");
Question.Input("2+2")
```
![][input-img]#### Password
```csharp
Question.Password("Type password");
```
![][password-img]#### Menu
```csharp
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.
```csharp
.Page(int pageSize)
```Default value(s) to use if nothing is entered.
```csharp
.WithDefaultValue(...)
args:
TResult defaultValue
List defaultValues : for list types and types implementing IComparable
Func compareTo : for list types not implementing IComparable```
Chosen value displayed for final confirmationFor password type, user have to confirm password by typing it again
```csharp
.WithConfirmation()
```Set display name for complex type
```csharp
.WithConvertToString(Func 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.
```csharp
.WithValidation(Func fn, string errorMessage)
.WithValidation(Func fn, Func errorMessageFn)
```## Inquirer
```csharp
_test = new Inquirer();
```
Inquirer is for preserving history
It supports
- navigation
- optional prompts
- hierarchical prompts```csharp
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();
```