ConsoleMenuDN 0.1.6

dotnet add package ConsoleMenuDN --version 0.1.6
                    
NuGet\Install-Package ConsoleMenuDN -Version 0.1.6
                    
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="ConsoleMenuDN" Version="0.1.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConsoleMenuDN" Version="0.1.6" />
                    
Directory.Packages.props
<PackageReference Include="ConsoleMenuDN" />
                    
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 ConsoleMenuDN --version 0.1.6
                    
#r "nuget: ConsoleMenuDN, 0.1.6"
                    
#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 ConsoleMenuDN@0.1.6
                    
#: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=ConsoleMenuDN&version=0.1.6
                    
Install as a Cake Addin
#tool nuget:?package=ConsoleMenuDN&version=0.1.6
                    
Install as a Cake Tool

ConsoleMenuDN

.NET
GitHub

ConsoleMenuDN is a helper library for creating interactive menus within console applications. This library simplifies the process of building and managing console-based menus, making it easier to create user-friendly command-line interfaces.

image

Features

  • Easy-to-use API for creating console menus.
  • Support for asynchronous menu actions.
  • Automatic handling of key inputs (navigation, selection).
  • Responsive to console window resize events.

Installation

You can install the ConsoleMenuDN package via NuGet:

dotnet add package ConsoleMenuDN

Usage

Basic Example

Here's a simple example of how to use ConsoleMenuDN to create a console menu:

using ConsoleMenuDN;

class Program
{
    static void Main(string[] args)
    {
        MainMenu();
    }

    private static void MainMenu()
    {
        List<MenuItem> menuOptions = new List<MenuItem>
        {
            new MenuItem("Fetch something", () => Console.WriteLine("Fetching")),
            new MenuItem("Process something", () => Console.WriteLine("Processing")),
            new MenuItem("Save something", () => Console.WriteLine("Saving")),  
            new MenuItem("Exit", () => Environment.Exit(0))
        }; 

        var menu = new MenuManager(menuOptions, "Menu");
        menu.Show();
    }
}

Displaying the Menu

To display the menu, create an instance of MenuManager and call the Show method:

var menu = new MenuManager(menuOptions, "Main Menu");
menu.Show();

Creating Sub-Menus

To use a sub-menu, create another instance of MenuManager with the desired MenuItems and call this from the parent menu.

ConsoleMenuDN isn't smart, you need to manage 'return to previous menu' options yourself. You can create a sub-menu with the ability to return to its parent by following this pattern:

using ConsoleMenuDN;

namespace ConsoleMenuDemo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            MainMenu();
        }

        private static void MainMenu()
        {
            List<MenuItem> menuOptions = new List<MenuItem>
            {
                new MenuItem("Fetch something", () => Console.WriteLine("Fetching")),
                new MenuItem("Process something", () => Console.WriteLine("Processing")),
                new MenuItem("Save something", () => Console.WriteLine("Saving")),
                new MenuItem("A Sub-Menu", () => NestedMenu()),  
                new MenuItem("Exit", () => Environment.Exit(0))
            }; 

            var menu = new MenuManager(menuOptions, "Menu");
            menu.Show();
        }
 
        private static void NestedMenu()
        {
            List<MenuItem> menuOptions = new List<MenuItem>
            {
                new MenuItem("Return to Main Menu", () =>  MainMenu()),
                new MenuItem("Execute task A", () => Console.WriteLine("Executing Task A")),
                new MenuItem("Execute task B", () => Console.WriteLine("Executing Task B"))              
            };

            var secondMenu = new MenuManager(menuOptions, "A Sub-Menu");
            secondMenu.Show();
        }        
    }
}

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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
0.1.6 245 6/23/2024
0.1.5 150 6/23/2024
0.1.4 177 6/19/2024
0.1.3 179 6/19/2024
0.1.2 177 6/19/2024
0.1.1 159 6/19/2024
0.0.8 156 6/19/2024
0.0.7 156 6/19/2024
0.0.6 142 6/19/2024
0.0.5 163 6/19/2024
0.0.4 172 6/19/2024
0.0.3 174 6/19/2024
0.0.2 163 6/19/2024
0.0.1 162 6/19/2024