void PrintOptions(int skip, int take) { var keys = dictionary.Keys.ToList(); var max = Math.Min(keys.Count, skip + take); for (int i = skip; i < max; i++) { var key = keys[i]; string?value = separators.TryGetC(i); if (value.HasText()) { Console.WriteLine(); Console.WriteLine(value); } SafeConsole.WriteColor(ConsoleColor.White, " " + keys[i]); Console.WriteLine(" - " + dictionary[key].Description); } if (skip + take >= dictionary.Count) { return; } SafeConsole.WriteColor(ConsoleColor.White, " +"); Console.WriteLine(" - " + ConsoleMessage.More.NiceToString()); }
public static T WaitQuery <T>(string startingText, Func <T> query) { T result = default(T); SafeConsole.WriteColor(ConsoleColor.Yellow, startingText); WaitExecute(() => { result = query(); Console.WriteLine(); }); return(result); }
public static int WaitRows(string startingText, Func <int> updateOrDelete) { SafeConsole.WriteColor(ConsoleColor.Gray, startingText); int result = 0; WaitExecute(() => { result = updateOrDelete(); lock (SafeConsole.SyncKey) { SafeConsole.WriteColor(ConsoleColor.White, " {0} ", result); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, "rows afected"); } }); return(result); }
public WithDescription <V> ChooseTuple(string endMessage) { retry: try { var step = Console.WindowHeight - 10; Console.WriteLine(welcomeMessage); for (int i = 0; i < dictionary.Count; i += step) { PrintOptions(i, step); if (i + step < dictionary.Count) { SafeConsole.WriteColor(ConsoleColor.White, " +"); Console.WriteLine(" - " + ConsoleMessage.More.NiceToString()); } Console.WriteLine(endMessage); string line = Console.ReadLine(); if (string.IsNullOrEmpty(line)) { return(null); } if (line.Trim() == "+") { continue; } Console.WriteLine(); return(GetValue(line.Trim())); } return(null); } catch (Exception e) { Console.WriteLine(e.Message); goto retry; } }
public static void WaitExecute(Action action) { if (Console.IsOutputRedirected) { action(); return; } int?result = null; try { int left = Console.CursorLeft; DateTime dt = DateTime.Now; Task t = Task.Factory.StartNew(() => { while (result == null) { var str = " (" + (DateTime.Now - dt).NiceToString(DateTimePrecision.Seconds) + ")"; Console.SetCursorPosition(Math.Max(0, Math.Min(left, Console.WindowWidth - str.Length - 1)), Console.CursorTop); lock (SafeConsole.SyncKey) SafeConsole.WriteColor(ConsoleColor.DarkGray, str); Thread.Sleep(1000); } }); action(); } finally { result = -1; } }