public void Run() { while (true) { ColoredConsole.Write(ConsoleColor.White, "> "); var command = Console.ReadLine(); var timer = Stopwatch.StartNew(); try { log.Info($"Executing '{command}'"); Execute(command); log.Info($"Executing '{command}' completed"); } catch (Exception ex) { if (ex is AggregateException) { ex = ((AggregateException)ex).InnerException; } ColoredConsole.WriteLine(ConsoleColor.DarkRed, "Error: ", ConsoleColor.Red, ex.GetType().Name); ColoredConsole.WriteLine(ConsoleColor.Red, ex.Message); log.Error($"Error in command `{command}`", ex); } finally { if (MeasureTime) { ColoredConsole.WriteLine(ConsoleColor.DarkYellow, $"Execution time - {timer.Elapsed}"); } } } }
public async Task Info() { var o = Console.ForegroundColor; var r = ConsoleColor.Red; var g = ConsoleColor.Green; var b = ConsoleColor.Cyan; var sizes = await Hosting.GetSpaceInfoAsync(); var total = sizes.TotalSpace.TotalBytes; var usedPercent = total == 0 ? 0 : 100 * sizes.UsedSpace.TotalBytes / total; var freePercent = total == 0 ? 0 : 100 * sizes.FreeSpace.TotalBytes / total; ColoredConsole.WriteLine(o, "Used ", r, sizes.UsedSpace, o, " from ", b, sizes.TotalSpace, o, " - ", r, usedPercent, "%"); ColoredConsole.WriteLine(o, "Free ", g, sizes.FreeSpace, o, " from ", b, sizes.TotalSpace, o, " - ", g, freePercent, "%"); var maxCells = Console.WindowWidth - 1; var usedCells = maxCells * usedPercent / 100; ColoredConsole.Write(r, string.Join("", Enumerable.Repeat("|", (int)usedCells))); ColoredConsole.WriteLine(g, string.Join("", Enumerable.Repeat(".", maxCells - (int)usedCells))); }