private static void RunSelection(TodoCollection todoCollection, string choice) { var todoSelection = todoCollection.FindById(choice); Print.Line($"You selected: ", clearConsole: true); Print.NewLine(todoSelection.Description, todoSelection.Color); Print.Line($"Priority level is: "); Print.NewLine(todoSelection.PriorityLevel.ToString(), Priority.GetColor(todoSelection.PriorityLevel)); var menu = new CharConsoleMenu() { Choices = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("d", "escription edit"), new KeyValuePair <string, string>("p", "riority edit"), new KeyValuePair <string, string>("r", "emove") }, SpacingCount = 0, IdWrapColor = ConsoleColor.Yellow, TextColor = ConsoleColor.Blue }; menu.OutputToConsole("Please make a selection", ConsoleColor.Green); string modify = menu.GetUserInput().ToLower(); if (modify == menu.Choices[0].Key.ToString()) // d { string newDescription = GetNewDescription(todoSelection, todoCollection); if (!string.IsNullOrEmpty(newDescription)) { todoCollection.Update(todoSelection, new Todo() { Description = newDescription, PriorityLevel = todoSelection.PriorityLevel }); todoCollection.Save(); } } else if (modify == menu.Choices[1].Key.ToString()) // p { todoCollection.Update(todoSelection, new Todo() { Description = todoSelection.Description, PriorityLevel = GetPriorityForNewEntry() }); todoCollection.Save(); } else if (modify == menu.Choices[2].Key.ToString()) // r { todoCollection.Remove(todoSelection); todoCollection.Save(); } }
private static void RunLoop(string todoPath) { if (!string.IsNullOrEmpty(todoPath)) { bool keepRunning; do { keepRunning = Run(todoPath); } while (keepRunning); } else { Print.NewLines(new string[] { "This program requires one argument passed to it.", "Pass a path to an empty .txt file, then try running the program again." }, ConsoleColor.Red); var menu = new CharConsoleMenu() { Choices = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("y", "es"), new KeyValuePair <string, string>("n", "o") }, SpacingCount = 0, IdWrapColor = ConsoleColor.Cyan }; Print.NewLines(new string[] { "Or, would you like to create a new db at the following path", DefaultDbPath, "?" }, ConsoleColor.Yellow); menu.OutputToConsole(skipBeforeMessage: true); string choice = menu.GetUserInput().ToLower(); if (choice == "y") { File.WriteAllText(DefaultDbPath, string.Empty, Encoding.Default); RunLoop(DefaultDbPath); } } }
private static PriorityLevel GetPriorityForNewEntry() { var priority = PriorityLevel.None; var menu = new CharConsoleMenu(); menu.TextColor = ConsoleColor.Yellow; menu.SetNumberedChoices(Enum.GetNames(typeof(PriorityLevel)).ToList()); menu.OutputToConsole( afterMessage: "Just pressing enter will select None.", beforeMessage: "Select priority level", beforeMessageColor: ConsoleColor.Green); var selection = menu.GetUserInput(); { if (selection != '\r'.ToString()) { Enum.TryParse(menu.Choices.Where(x => x.Key == selection).Single().Value, out priority); } } return(priority); }