// Receives a string array and x and y coordinates to create the interactive menu at the x and y coordinates public static int Selection(string[] menuItems, int x, int y, string menuMessage) { var menu = new Menu(menuItems); var countOfMenuItems = menuItems.Count(); var menuPainter = new ConsoleMenuPainter(menu); bool done = false; Console.WriteLine(menuMessage); x = Console.CursorLeft + x; y = Console.CursorTop + y + 1; do { menuPainter.Paint(x, y); var keyInfo = Console.ReadKey(true); menu.SelectedIndex = AlternateInputSelection(ref done, keyInfo, menu.SelectedIndex, countOfMenuItems); if (done) { return(menu.SelectedIndex); } switch (keyInfo.Key) { case ConsoleKey.UpArrow: menu.MoveUp(); break; case ConsoleKey.DownArrow: menu.MoveDown(); break; case ConsoleKey.Enter: done = true; Console.ResetColor(); return(menu.SelectedIndex); default: break; } }while (!done); Console.ForegroundColor = ConsoleColor.Cyan; // Console.WriteLine("Selected option: " + (menu.SelectedOption ?? "(nothing)")); Console.ReadKey(); return(9); }
private void EventLoop() { string menuMessage = "\n\nPASSWORD AUTHENTICATION SYSTEM" + "\nMake your choice using the arrow keys or the numbers, then (ENTER)" + "\nWhat would you like to do:"; bool finished = false; do { ConsoleMenuPainter.TextColor(); string[] menuItems = new string[] { "1) Establish an account", "2) Authenticate a user", "3) See a real time hash text as you type", "4) Quit" }; Console.Clear(); int userChoice = Menu.Selection(menuItems, Console.CursorLeft + 1, Console.CursorTop, menuMessage); switch (userChoice) { case 0: EstablishAccount(); break; case 1: AuthenticateUser(); break; case 2: RealTimeHashDemo(); break; case 3: finished = true; break; default: Console.WriteLine("Default case"); break; } } while (!finished); }