ConsoleTools
ConsoleTools copied to clipboard
Console Messge
I'm starting using this tools , but have some questions
- Whe select an menu option and execute an action immediate close the menu, Does I need to put inside an while(true) loop?
- 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
Hi,
- Yes, you need the
Displaymethod to be executed inside awhile (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;
}
}
- 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?
Attached ticket: #107
I made a quick fix and released the version 1.2.1 Check if it is working for you now.