- Notifications
You must be signed in to change notification settings - Fork17
A simple, highly customizable, DOS-like console menu
License
lechu445/ConsoleMenu
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A simple, highly customizable, DOS-like console menu
Nuget package:https://www.nuget.org/packages/ConsoleMenu-simple
varsubMenu=newConsoleMenu(args,level:1).Add("Sub_One",()=>SomeAction("Sub_One")).Add("Sub_Two",()=>SomeAction("Sub_Two")).Add("Sub_Three",()=>SomeAction("Sub_Three")).Add("Sub_Four",()=>SomeAction("Sub_Four")).Add("Sub_Close",ConsoleMenu.Close).Configure(config=>{config.Selector="--> ";config.EnableFilter=true;config.Title="Submenu";config.EnableBreadcrumb=true;config.WriteBreadcrumbAction= titles=>Console.WriteLine(string.Join(" / ",titles));});varmenu=newConsoleMenu(args,level:0).Add("One",()=>SomeAction("One")).Add("Two",()=>SomeAction("Two")).Add("Three",()=>SomeAction("Three")).Add("Sub",subMenu.Show).Add("Change me",(thisMenu)=>thisMenu.CurrentItem.Name="I am changed!").Add("Close",ConsoleMenu.Close).Add("Action then Close",(thisMenu)=>{SomeAction("Close");thisMenu.CloseMenu();}).Add("Exit",()=>Environment.Exit(0)).Configure(config=>{config.Selector="--> ";config.EnableFilter=true;config.Title="Main menu";config.EnableWriteTitle=true;config.EnableBreadcrumb=true;});menu.Show();
To do this, usepublic ConsoleMenu(string[] args, int level) constructor during initialization.Use double quotes for item names and digits for item numbers. Here are some examples:
--menu-select=0.1//run first at level 0 and second at level 1--menu-select="Sub.Sub_One.'Close...'"//run "Sub" at level 0 and "Sub_One" at level 1, and "Close..." at level 2--menu-select="Sub.2"//run item "Sub" at level 0, and then run third item at level 1
You can also define configuration via .Configure() method. The default config looks like:
publicclassMenuConfig{publicConsoleColorSelectedItemBackgroundColor=Console.ForegroundColor;publicConsoleColorSelectedItemForegroundColor=Console.BackgroundColor;publicConsoleColorItemBackgroundColor=Console.BackgroundColor;publicConsoleColorItemForegroundColor=Console.ForegroundColor;publicEncodingInputEncoding=Console.InputEncoding;publicEncodingOutputEncoding=Console.OutputEncoding;publicActionWriteHeaderAction=()=>Console.WriteLine("Pick an option:");publicAction<MenuItem>WriteItemAction= item=>Console.Write("[{0}] {1}",item.Index,item.Name);publicstringSelector=">> ";publicstringFilterPrompt="Filter: ";publicboolClearConsole=true;publicboolEnableFilter=false;publicstringArgsPreselectedItemsKey="--menu-select=";publiccharArgsPreselectedItemsValueSeparator='.';publicboolEnableWriteTitle=false;publicstringTitle="My menu";publicAction<string>WriteTitleAction= title=>Console.WriteLine(title);publicboolEnableBreadcrumb=false;publicAction<IReadOnlyList<string>>WriteBreadcrumbAction= titles=>Console.WriteLine(string.Join(" > ",titles));publicboolEnableAlphabet=false;}
Example:
newConsoleMenu().Add("One",()=>SomeAction("One")).Add("Two",()=>SomeAction("Two")).Add("Close",ConsoleMenu.Close).Configure(config=>{config.Selector="--> ";}).Show();
Framework compatible with .NET Standard 1.3 (.NET Core 1.0, .NET Framework 4.6, Mono 4.6) or higher.
About
A simple, highly customizable, DOS-like console menu
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.
