Console.Menus 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Console.Menus --version 1.0.2                
NuGet\Install-Package Console.Menus -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="Console.Menus" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Console.Menus --version 1.0.2                
#r "nuget: Console.Menus, 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.
// Install Console.Menus as a Cake Addin
#addin nuget:?package=Console.Menus&version=1.0.2

// Install Console.Menus as a Cake Tool
#tool nuget:?package=Console.Menus&version=1.0.2                

Console Menus

A simple, yet powerful implementation of console menus.

Example

Here is an example of a demo app built using this package: The demo

Note : Everything is controlled by the up/down arrow keys and the enter/esc key

User usage

Key Usage
↑ Up arrow key Move up in menu
↓ Down arrow key Move down in menu
↳ Enter key Select an item in the menu
↰ Escape key Go back to the previous menu (if exits)
Ctrl + C keys Exit the menu by forcing it to stop

Code Usage

You can start by creating a MainMenu object which will be responsible to run all of your other menus/items like this:

MainMenu mainMenu = MainMenu.Create("My main menu");

Then you can start adding menus and/or items to the main menu

mainMenu.AddMenu("My first sub menu");
IMenu subMenu = (mainMenu[0] as IMenu);
subMenu.AddItem("My first sub-sub item");

The casting is necessary because all the items a menu contains are by default of type IMenuItem. In order to access the IMenu members, we will need to cast the item to IMenu.

You can also add listeners to when the users selects the item like this:

int count = 0;
var item = (subMenu[0] as MenuItem);
item.ActionToPerform += (sender, args) => {
    count++;
    System.Console.WriteLine("I have been selected " + count + " time(s)");
};

The following code increments count by 1 each time the users selects the item - item. And then proceeds to print the count. (e.g. "I have been selected 1 time(s)")

In order to run the menus you'll need to call the MainMenu.Run() method.

// In order to run
mainMenu.Run();
// In order to stop
mainMenu.Stop();

Class Hierarchy

Here is a diagram explaining the hierarchy of the project to give you a better understanding of the project The project hierarchy

Help

Any problems? questions? suggestions? Contact me:

  • Mail - yishai.israel8@gmail.com
  • Here, write an issue or comment on this repository
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

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.1.0 470 8/16/2022
1.0.2 409 8/3/2022
1.0.1 416 8/2/2022

Added a README to the package, and made code easier to understand