MenuMan 1.0.5
dotnet add package MenuMan --version 1.0.5
NuGet\Install-Package MenuMan -Version 1.0.5
<PackageReference Include="MenuMan" Version="1.0.5" />
<PackageVersion Include="MenuMan" Version="1.0.5" />
<PackageReference Include="MenuMan" />
paket add MenuMan --version 1.0.5
#r "nuget: MenuMan, 1.0.5"
#:package MenuMan@1.0.5
#addin nuget:?package=MenuMan&version=1.0.5
#tool nuget:?package=MenuMan&version=1.0.5
MenuMan
By Tyson Jones
A simple terminal-style menu for obtaining user input. Inspried heavily by inquirer.
Usage
var menu = new Menu(
Questions.NumberInput<int>("money", "How much money do you have?", defaultValue: 33),
Questions.TextInput("lastName", "What is your last name?", defaultValue: "Tyson"),
Questions.ListInput("favoriteFood", "What is your favorite food?", availableFoods),
Questions.CheckboxInput("favoriteSongs", "What are your favorite songs?", availableSongs),
Questions.ConfirmInput("isWeird", "Are you weird?"));
var answers = menu.Go();
Console.WriteLine(answers.Get<int>("money")); // Prints 33 or whatever I typed in.
// Or you can cast the result manually.
Console.WriteLine((int)answers["money"]);
API
MenuclassRepresents a menu object with a fixed number of questions. Constructed by the only available constructor.
Constructor Signature
public Menu(params IQuestion[] questions)Methods
Go- Shows the menu. Each question handed to the constructor is asked in the order they were handed to the constructor.
- Returns a
Dictionary<string, object>where the keys represents the question keys and the values represent the user's responses.
NumberInput<T>classRepresents a simple single-line text input that filters out all non-numeric keys and only accepts valid input for the given numeric type. Constructed by the
Questions.NumericInput<T>method.The answers object type is
T.Signature
public static IQuestion NumberInput<T>(string key, string questionText, Func<Dictionary<string, object>, bool> condition = null, T? defaultValue = null) where T : struct;Parameters
T- The numeric type desired to be used for parsing and validation.key- The question key.questionText- The question message to display to the user.condition- Optional. A predicate to determine if the question should be asked. The current answers are passed as the only parameter.defaultValue- Optional. The default value ofTto prompt to the user.
ConfirmInputclassRepresents a boolean input in the form of Yes/No. Constructed by the
Questions.ConfirmInputmethod.The answers object type is
YesNo.Signature
public static IQuestion ConfirmInput(string key, string questionText, Func<Dictionary<string, object>, bool> condition = null, YesNo defaultValue = YesNo.Yes);Parameters
key- The question key.questionText- The question message to display to the user.condition- Optional. A predicate to determine if the question should be asked. The current answers are passed as the only parameter.defaultValue- Optional. This value will be selected if the user presses enter immediately after prompted for input.
CheckboxInputclassRepresents a listbox for selecting multiple items. Constructed by the
Questions.NumericInputmethod.The answers object type is
string[].Signature
public static IQuestion CheckboxInput(string key, string questionText, string[] options, Func<Dictionary<string, object>, bool> condition = null, bool allowEmptyInput = false, string[] defaultValue = null, int pageSize = 10, bool disableSearch = false, bool showSearchOptions = true);Parameters
key- The question key.questionText- The question message to display to the user.options- The items to display in the listbox.condition- A predicate to determine if the question should be asked. The current answers are passed as the only parameter.allowEmptyInput- If true, an empty string array can be returned if the user selected no items.defaultValue- The items that will start out selected when the listbox is shown.pageSize- An options array larger than this number will force the user to scroll to see all available choices.disableSearch- If true, the user will be unable to filter the choices.showSearchOptions- If false, the helper lines shown at the bottom of the terminal showing your current search mode and some selection options will not be shown.
ListInputclassRepresents a listbox for selecting a single item. Constructed by the
Questions.ListInputmethod.The answers object type is
string.Signature
public static IQuestion ListInput(string key, string questionText, string[] options, Func<Dictionary<string, object>, bool> condition = null, bool allowEmptyInput = false, string defaultValue = "", int pageSize = 10, bool disableSearch = false, bool showSearchOptions = true);Parameters
key- The question key.questionText- The question message to display to the user.options- The items to display in the listbox.condition- Optional. A predicate to determine if the question should be asked. The current answers are passed as the only parameter.allowEmptyInput- Optional. If true, null can be returned if the user's search term has filtered out all available items.defaultValue- Optional. The default selection to highlight when the listbox is shown. If this item isn't present in the options array, the first item in the options array will be highlighted.pageSize- Optional. An options array larger than this number will force the user to scroll to see all available choices.disableSearch- Optional. If true, the user will be unable to filter the choices.showSearchOptions- Optional. If false, the helper line shown at the bottom of the terminal showing your current search mode will not be shown.
TextInputclassRepresents a simple single-line text input. Constructed by the
Questions.TextInputmethod.The answers object type is
string.Signature
public static IQuestion TextInput(string key, string questionText, Func<Dictionary<string, object>, bool> condition = null, bool allowEmptyInput = false, string defaultValue = "");Parameters
key- The question key.questionText- The question message to display to the user.condition- Optional. A predicate to determine if the question should be asked. The current answers are passed as the only parameter.allowEmptyInput- Optional. If true, the empty string is accepted as valid input.defaultValue- Optional. The default string to prompt to the user.
Getextension methodAttempts to retrieve the value at the specified key in the answers dictionary, casting the result to T if successful and returning the default value for T if unsuccessful. If the cast is unsuccessful, an exception will be thrown.
Signature
public static T Get<T>(this IDictionary<string, object> dictionary, string key)Parameters
T- The type to which to cast the result.dictionary- The input dictionary.key- The key.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.1 is compatible. |
| .NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.