Console.Menus
1.0.2
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
<PackageReference Include="Console.Menus" Version="1.0.2" />
paket add Console.Menus --version 1.0.2
#r "nuget: Console.Menus, 1.0.2"
// 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:
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
by1
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
Help
Any problems? questions? suggestions? Contact me:
- Mail - yishai.israel8@gmail.com
- Here, write an issue or comment on this repository
Product | Versions 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. |
-
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.
Added a README to the package, and made code easier to understand