lastunicorn / ConsoleTools

A set of tools and "controls" for the .net Console.
GNU General Public License v3.0
73 stars 5 forks source link

Console Messge #106

Open charga opened 1 month ago

charga commented 1 month ago

I'm starting using this tools , but have some questions

  1. Whe select an menu option and execute an action immediate close the menu, Does I need to put inside an while(true) loop?
  2. My application display a lot of console message, but it always appears on top, I need to appears below all an when finished show menus again

It's the a sample like that? How can I do?

Regards

lastunicorn commented 1 month ago

Hi,

  1. Yes, you need the Display method to be executed inside a while (true) loop Here is an example:
internal static class Program
{
    public static bool ExitWasRequested { get; set; }

    private static void Main(string[] args)
    {
        ScrollMenu scrollMenu = new();

        scrollMenu.AddItems(new[]
            {
                new LabelMenuItem
                {
                    Text = "Item 1",
                    Command = new Item1Command()
                },
                new LabelMenuItem
                {
                    Text = "Item 2",
                    Command = new Item2Command()
                },
                new LabelMenuItem
                {
                    Text = "Item 3",
                    Command = new Item3Command()
                },
                new LabelMenuItem
                {
                    Text = "Exit",
                    Command = new ExitCommand()
                }
            }
        );

        while (!ExitWasRequested)
            scrollMenu.Display();
    }
}

internal class Item1Command : ICommand
{
    public bool IsActive => true;

    public void Execute()
    {
        CustomConsole.WriteLine("Item 1 was selected.");
    }
}

internal class Item2Command : ICommand
{
    public bool IsActive => true;

    public void Execute()
    {
        CustomConsole.WriteLine("Item 2 was selected.");
    }
}

internal class Item3Command : ICommand
{
    public bool IsActive => true;

    public void Execute()
    {
        CustomConsole.WriteLine("Item 3 was selected.");
    }
}

internal class ExitCommand : ICommand
{
    public bool IsActive => true;

    public void Execute()
    {
        CustomConsole.WriteLine("Exit was selected.");
        Program.ExitWasRequested = true;
    }
}
  1. Regarding your second topic, I think you discovered a bug. After the user selects an item, the cursor should already be placed after the menu and any text written to the console should be written after the menu. What version of Windows are you using? Is it Windows 11?
lastunicorn commented 1 month ago

Attached ticket: #107

lastunicorn commented 1 month ago

I made a quick fix and released the version 1.2.1 Check if it is working for you now.