/// <summary> /// Render options and return selected ones /// </summary> /// <returns></returns> private IEnumerable <int> RenderAndSelectOptions() { List <int> selected = new List <int>(); var startAt = 0; var row = 0; Console.CursorVisible = false; ConsoleBuffer.MemoriseBufferPosition(BUFFER_NAME); bool exit = false; while (!exit || selected.Count == 0) { RenderOptions(selected, startAt, row); var key = Console.ReadKey(); // Update params according to key press (exit, startAt, row, selected) = ExecuteAction(key.Key, startAt, row, selected); } Console.CursorVisible = true; return(selected); }
private static async void StartDemo() { const string NAME = "#BUFFER_SELECTION123#"; ConsoleBuffer.MemoriseBufferPosition(NAME); Console.WriteLine("Select 1 option"); var selection = InputSelection.From <TestClass>() .AddOption(new TestClass { Name = "option1" }) .AddOption(new TestClass { Name = "option2" }) .AddOption(new TestClass { Name = "option3" }) .AddOption(new TestClass { Name = "option4" }); var result1 = await selection.RequestInput(); Console.WriteLine($"Selected => {result1.First()}"); ConsoleI.AwaitContinue(); ConsoleBuffer.ClearBufferFrom(NAME); Console.WriteLine("Select 1 to 5 options"); var selection2 = InputSelection.From <TestClass>() .SetMaxSelected(5) .AddOption(new TestClass { Name = "option1" }) .AddOption(new TestClass { Name = "option2" }) .AddOption(new TestClass { Name = "option3" }) .AddOption(new TestClass { Name = "option4" }) .AddOption(new TestClass { Name = "option5" }) .AddOption(new TestClass { Name = "option6" }) .AddOption(new TestClass { Name = "option7" }) .AddOption(new TestClass { Name = "option8" }) .AddOption(new TestClass { Name = "option9" }) .AddOption(new TestClass { Name = "option10" }) .AddOption(new TestClass { Name = "option11" }); var result2 = await selection2.RequestInput(); foreach (var r in result2) { Console.WriteLine($"Selected => {r}"); } ConsoleI.AwaitContinue(); ConsoleBuffer.ClearBufferFrom(NAME); Console.WriteLine("Also works with ENUM"); var result3 = await InputSelection .FromEnum <EnumTest>() .RequestInput(); foreach (var r in result3) { Console.WriteLine($"Selected => {(int)r}"); } ConsoleI.AwaitContinue(); ConsoleBuffer.ClearBufferFrom(NAME); }