// Copyright Epic Games, Inc. All Rights Reserved. using System; namespace EpicGames.Core { /// /// Utility methods for writing to the console /// public static class ConsoleUtils { /// /// Gets the width of the window for formatting purposes /// public static int WindowWidth { get { // Get the window width, using a default value if there's no console attached to this process. int newWindowWidth; try { newWindowWidth = Console.WindowWidth; } catch { newWindowWidth = 240; } if (newWindowWidth <= 0) { newWindowWidth = 240; } return newWindowWidth; } } /// /// Writes the given text to the console as a sequence of word-wrapped lines /// /// The text to write to the console public static void WriteLineWithWordWrap(string text) { WriteLineWithWordWrap(text, 0, 0); } /// /// Writes the given text to the console as a sequence of word-wrapped lines /// /// The text to write to the console /// Indent for the first line /// Indent for lines after the first public static void WriteLineWithWordWrap(string text, int initialIndent, int hangingIndent) { foreach (string line in StringUtils.WordWrap(text, initialIndent, hangingIndent, WindowWidth)) { Console.WriteLine(line); } } /// /// Writes an colored warning message to the console /// /// The message to output public static void WriteWarning(string text) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(text); Console.ResetColor(); } /// /// Writes an colored error message to the console /// /// The message to output public static void WriteError(string text) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(text); Console.ResetColor(); } } }