Console.Menus 1.1.0

dotnet add package Console.Menus --version 1.1.0                
NuGet\Install-Package Console.Menus -Version 1.1.0                
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.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Console.Menus --version 1.1.0                
#r "nuget: Console.Menus, 1.1.0"                
#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.1.0

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

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 Menu object which will be responsible to run all of your other menus/items like this:

Menu mainMenu = new Menu("My first menu");

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

mainMenu.AddMenu("My first sub menu");
IMenu subMenu = ((IMenu) mainMenu[0]);
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 menu you'll need to call the IMenu.Run() method. And IMenu.Stop() in order to stop.

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

Extra - you can also create menus in this syntax - (which may be more readable in certain cases):

var mm = new Menu("My main menu")
        {
            new Menu("My sub menu")
            {
                new Menu("My sub-sub menu")
                {
                    new MenuItem("Print Hello World", (sender, args) => {
                        System.Console.WriteLine("Hello World");
                    })
                },
                new MenuItem("Click me", (sender, args) => {
                    System.Console.WriteLine("I have been clicked :)");
                }),
                new MenuItem("Stop menu", (sender, args) => {
                    var thisItem = ((IMenuItem) sender);
                    thisItem.Parent.Stop();
                })
            }
        };
        mm.Run();

Class Hierarchy

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

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

Removed MainMenu Class.
Improved Menu Addition.
You can now run any menu, not just the MainMenu.