using System.Globalization; using TirsvadCLI.MenuPaginator; namespace Example; internal class Example { static void SomeAction() { Console.Clear(); Console.WriteLine("Some action"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); } static void SomeOtherAction() { Console.Clear(); Console.WriteLine("Some other action"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); } static void SomeActionWithParameter(string parameter) { Console.Clear(); Console.WriteLine($"Some action with parameter: {parameter}"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); } /// /// Example of a menu with only one page /// static void MenuExample1() { Console.Clear(); Console.WriteLine("Example of a menu\n"); List menuItems = new() { new MenuItem("Some action to do", (Action)SomeAction) }; MenuPaginator menu = new(menuItems, 10, true); if (menu.menuItem != null && menu.menuItem.Action is Action action) { action(); } } /// /// Example of a menu with more than one page /// Having a category in the menu /// Limit to 10 items per page /// static void MenuExample2() { Console.Clear(); Console.WriteLine("Example of a menu with more than one page\n"); List menuItems = new() { new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", (Action)SomeOtherAction), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", (Action)SomeOtherAction), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("A category", null), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", (Action)SomeOtherAction), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", (Action)SomeOtherAction), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", new Action(() => { SomeActionWithParameter("Hello"); })), }; MenuPaginator menu = new(menuItems, 10); if (menu.menuItem != null && menu.menuItem.Action is Action action) { action(); } } static void MenuExample3() { CultureInfo.CurrentUICulture = new CultureInfo("da-DK"); Console.Clear(); Console.WriteLine("Example of a menu with more than one page and languages set to Danish\n"); List menuItems = new() { new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", (Action)SomeOtherAction), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", (Action)SomeOtherAction), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("A category", null), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", (Action)SomeOtherAction), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", (Action)SomeOtherAction), new MenuItem("Some action to do", (Action)SomeAction), new MenuItem("Some action action to do", new Action(() => { SomeActionWithParameter("Hello"); })), }; MenuPaginator menu = new(menuItems, 10); if (menu.menuItem != null && menu.menuItem.Action is Action action) { action(); } } static void Main(string[] args) { MenuExample1(); MenuExample2(); MenuExample3(); // Forced culture to da-DK } }