Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console Messge #106

Open
charga opened this issue Sep 4, 2024 · 3 comments
Open

Console Messge #106

charga opened this issue Sep 4, 2024 · 3 comments
Assignees

Comments

@charga
Copy link

charga commented Sep 4, 2024

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
Copy link
Owner

lastunicorn commented Sep 5, 2024

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 lastunicorn self-assigned this Sep 5, 2024
@lastunicorn
Copy link
Owner

Attached ticket: #107

@lastunicorn
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants