lechu445 / consolemenu Goto Github PK
View Code? Open in Web Editor NEWA simple, highly customizable, DOS-like console menu
License: MIT License
A simple, highly customizable, DOS-like console menu
License: MIT License
If i run the sample "ConsoleMenu/ConsoleMenuSampleApp/Program.cs" the Breadcrumb shows the text
"My menu / My menu" i would expect "Main menu / Submenu".
Do I understand something wrong or is it a bug?
Hi,
This looks like a really interesting project and I'd like to make use of it, but before I do, could I check what license you've released it under? Would you be able to add a license file to the repo?
Thanks,
Stephen
Hello.
I used your library to write a quick console application. However I found 2 limitations:
You'll find a patch for those modifications.
ConsoleMenu.cs.patch.txt
There is an issue with running app from console with pre-selected menu items, when there are more menu levels set up than requested item depth.
If levels 0,1,2 are configured, using --menu-select=0.1 results in IndexOutOfRangeException
locally fixed ConsoleMenu.cs line:106
// if (level <= items.Count)
if (level < items.Count)
Hi,
If you implement the IEnumerable interface in the ConsoleMenu
class, it will allow users to use collection initializers with no other changes required.
It is already possible to achieve this behavior by making a class that inherits from ConsoleMenu
and implementing the interface:
class MyConsoleMenu : ConsoleMenu, IEnumerable
{
public IEnumerator GetEnumerator() => Items.GetEnumerator();
}
This then allows me to use the collection initializer syntax, which I think looks way cleaner than chained methods:
var menu = new MyConsoleMenu()
{
{
"Some option",
() => { Log("You selected some option"); }
},
{
"Close menu",
menu => { Log("Closing the menu..."); menu.CloseMenu(); }
},
};
menu.Show();
The reason why this works is because a collection initializer requires the following:
IEnumerable
interface.Add
that have parameters.The second condition is already met, so all we need is the interface. The actual GetEnumerator()
is not actually used in the collection initializer constructor, but it still needs to be implemented (for reasons relating to ancient versions of .NET). Returning the items in the menu seems like the logical implementation.
I hope that this small change could be added to the ConsoleMenu class. It provides a nice syntax for those who want it and it does not affect any existing menus or uses.
In demo program, choose submenu, then submenu close, then submenu again...
You cannot get a second time in the menu
(probaby the close bool is not un-set)
Nice & clean little library for the rest!
[3] MenuItem 3
etc ?
Hi there,
great package, it gets you started real quick. I try to use it with some simple async code and Serilog logging. But as soon as I have executed the first menu action the Serilog logging won't work anymore.
It seem like the use of GetAwaiter().GetResult() is causing this.
Do you have any hints / recommendation on how to use async code in the menu actions?
So lonG
Daniel
Steps to Reproduce
menu.CloseMenu()
followed by menu.Show()
using ConsoleTools;
var menu = new ConsoleMenu(args, level: 0)
.Add("Test", Test)
.Add("Exit", () => Environment.Exit(0));
menu.Show();
return;
void Test(ConsoleMenu activeMenu)
{
activeMenu.CloseMenu();
activeMenu.Show();
}
Actual Behavior
The process fails with a stack overflow and a spam of stack traces:
Stack overflow.
at System.Collections.Generic.List`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
at ConsoleTools.ConsoleMenu.Show()
at Program.<<Main>$>g__Test|0_1(ConsoleTools.ConsoleMenu)
at ConsoleTools.ConsoleMenu+<>c__DisplayClass18_0.<Add>b__0(System.Threading.CancellationToken)
at ConsoleTools.ConsoleMenuDisplay+<ShowAsync>d__8.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[ConsoleTools.ConsoleMenuDisplay+<ShowAsync>d__8, ConsoleMenu, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null]](<ShowAsync>d__8 ByRef)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[ConsoleTools.ConsoleMenuDisplay+<ShowAsync>d__8, ConsoleMenu, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null]](<ShowAsync>d__8 ByRef)
at ConsoleTools.ConsoleMenuDisplay.ShowAsync(System.Threading.CancellationToken)
at ConsoleTools.ConsoleMenu.Show()
at Program.<<Main>$>g__Test|0_1(ConsoleTools.ConsoleMenu)
at ConsoleTools.ConsoleMenu+<>c__DisplayClass18_0.<Add>b__0(System.Threading.CancellationToken)
at ConsoleTools.ConsoleMenuDisplay+<ShowAsync>d__8.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[ConsoleTools.ConsoleMenuDisplay+<ShowAsync>d__8, ConsoleMenu, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null]](<ShowAsync>d__8 ByRef)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[ConsoleTools.ConsoleMenuDisplay+<ShowAsync>d__8, ConsoleMenu, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null]](<ShowAsync>d__8 ByRef)
at ConsoleTools.ConsoleMenuDisplay.ShowAsync(System.Threading.CancellationToken)
at ConsoleTools.ConsoleMenu.Show()
...
Expected Behavior
If calling Close()
inside an action is disallowed, it should be disallowed on the type, so it becomes a build error. If that's not feasible, there should at least be some checks to prevent the stack overflow.
like the title says =/
btw, thanks for the code.... useful
Would you be interested in adding support for titles and breadcrumbs? This would be so that you give each menu a title which is displayed at the top. As you drill down into lower level menus you'd get breadcrumbs to show you the menu structure that you're in e.g.
Main Menu -> Submenu 1 -> Submenu 2
I know that the heading can currently be modified, but I think it'd be nice to have baked in support for this.
First off, really nice library - just the level of complexity I want.
This isn't a bug so much as behaviour that felt unintuitive to me. The first thing I did was set up a menu action to print something with Console.WriteLine
.
var menu = new ConsoleMenu();
menu.Add("test", () => Console.WriteLine("hello world"));
menu.Show();
I was surprised when selecting this option seemed to do nothing! My first thought was the menus somehow took over stdout, so I had to close and re-show the menus when I wanted to print something. After looking at the example app for a bit, I figured out the real reason - without a Console.ReadKey()
, it loops back around to the menu too quickly for whatever your action might have printed out to be visible.
Given that 90% of what I might want to do is some variation on printing text, I think it would be useful to have a toggle in the Configure()
method that automatically inserts a ReadKey
after the supplied Action
has finished executing, maybe with some optional 'press any key' text.
Cheers!
i'm pretty sure the answer is no, but for a long menu is there a way to have the console scroll up/down to items that are off screen?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.