MenuMan 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package MenuMan --version 1.0.2
                    
NuGet\Install-Package MenuMan -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MenuMan" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MenuMan" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="MenuMan" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MenuMan --version 1.0.2
                    
#r "nuget: MenuMan, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MenuMan@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MenuMan&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=MenuMan&version=1.0.2
                    
Install as a Cake Tool

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

  • Represents 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> class

    Represents 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 of T to prompt to the user.
  • ConfirmInput class

    Represents a boolean input in the form of Yes/No. Constructed by the Questions.ConfirmInput method.

    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.
  • CheckboxInput class

    Represents a listbox for selecting multiple items. Constructed by the Questions.NumericInput method.

    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.
  • ListInput class

    Represents a listbox for selecting a single item. Constructed by the Questions.ListInput method.

    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.
  • TextInput class

    Represents a simple single-line text input. Constructed by the Questions.TextInput method.

    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.
  • Get extension method

    Attempts 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

  • .NETFramework 4.7.2

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 618 7/4/2022
1.0.4 570 7/4/2022
1.0.3 562 7/4/2022
1.0.2 535 7/4/2022
1.0.1 539 7/4/2022
1.0.0 543 6/28/2022