/// @short Принимает массив с названиями действий меню. /// @returns Выбраный заголовок. public static string Select(params string[] choices) { int selectedIndex = 0; ConsoleKey pressedKey = ConsoleKey.NoName; MyConsole.MoveCursorDown(choices.Length); while (pressedKey != ConsoleKey.Enter) { MyConsole.MoveCursorToBeginingOfLine(); MyConsole.MoveCursorUp(choices.Length); for (int choice = 0; choice < choices.Length; choice++) { string choiceTitle = choices[choice]; if (selectedIndex == choice) { Console.WriteLine($" > {MyConsole.ANSI_BOLD}{choiceTitle}{MyConsole.ANSI_RESET}"); } else { Console.WriteLine($" {choiceTitle}"); } } pressedKey = Console.ReadKey().Key; if (pressedKey == ConsoleKey.DownArrow) { if (selectedIndex < choices.Length - 1) { selectedIndex++; } else { selectedIndex = 0; } } else if (pressedKey == ConsoleKey.UpArrow) { if (selectedIndex > 0) { selectedIndex--; } else { selectedIndex = choices.Length - 1; } } } // Перемещаемся выше на 1, потому что, при нажатии Enter каретка сдвигается на 1 линию вниз MyConsole.MoveCursorUp(1); MyConsole.ClearLinesBeforeThis(choices.Length); // Двигаемся как раз к тому месту, где начиналось меню MyConsole.MoveCursorUp(choices.Length); return(choices[selectedIndex]); }
static void PrintProgressOf(string taskName, float completePercent) { int completePercentI = (int)Math.Ceiling(completePercent); Console.Write(new string('#', completePercentI)); Console.Write(new string(' ', BAR_LENGTH - completePercentI)); Console.WriteLine(string.Format(" {0:0.0}%", completePercent)); MyConsole.ClearLine(); Console.Write(taskName); MyConsole.MoveCursorUp(1); MyConsole.MoveCursorToBeginingOfLine(); }