Coder Social home page Coder Social logo

consolemenu's People

Contributors

epicguru avatar example123 avatar hallem avatar lechu445 avatar leszekbochenek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

consolemenu's Issues

Breadcrumb not working correctly

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?

Add license information

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

Close menu and update menu item improvements

Hello.

I used your library to write a quick console application. However I found 2 limitations:

  • I did not find a way to close a menu except by creating a menu item with the ConsoleMenu.Close action attached. I had a case where I needed the user to select something in a list. The menu is the list of available options and when the user "opens" one of the menu, it allows me to get the selected item. I needed that action to close the menu instead of forcing the user to select a menu item and then closing it manually through an additional menu item.
  • As the user selected something in a submenu, I needed a way to refresh a menu item. The menu item text had some text that depended on a selected value. When the user opens that menu item, it can select another value throught another menu. When that menu was closed I needed to update the current menu.

You'll find a patch for those modifications.
ConsoleMenu.cs.patch.txt

Issue with running app from console with pre-selected menu items

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)

Implement IEnumerable to allow collection initializer in ConsoleMenu.

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:

  1. That the class implements the IEnumerable interface.
  2. That the class has 1 or more public method with the name 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.

Reentry into submenu does not work

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!

How to use this library with async actions

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

StackOverflow when calling Show() on a pervious closed Menu and/or inside an Action

Steps to Reproduce

  1. Create a menu with an action that calls a function / delegate
  2. In the function / delegate call 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.

Menu titles and breadcrumbs

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.

Pause by default to allow Console.WriteLines to be seen

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.