/// @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]); }
/// @short Принимает массив с названиями действий меню и заголовок меню. /// @returns Выбраный заголовок. public static string Select(string prompt, params string[] choices) { Console.WriteLine($" {MyConsole.ANSI_ITALIC}{prompt}{MyConsole.ANSI_RESET}"); string result = Select(choices); // Убираем строку с текстом из prompt MyConsole.ClearLinesBeforeThis(1); MyConsole.MoveCursorUp(1); return(result); }
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(); }
public static void Load(List <Task> tasks) { float completePercent = 0; foreach (Task task in tasks) { PrintProgressOf(task.name, completePercent); task.action.Invoke(); completePercent += ((float)BAR_LENGTH) / tasks.Count; } PrintProgressOf(FINISHED_TITLE, 100.0f); #if !DEBUG Thread.Sleep(100); #endif // Полоска загрузки как раз занимает 2 линии MyConsole.ClearLine(); // Очищаем линию с текстом о завершении MyConsole.MoveCursorDown(1); MyConsole.ClearLine(); // Очищаем линию с полоской MyConsole.MoveCursorUp(1); }