// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Text; 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(); } } }