/// <summary> /// Writes a message to the with the current time to the screen, accepts a delegate object, /// redirecting execution to the appropriate method for printing the text /// in an appropriate colour. /// </summary> /// <param name="message">The message to be printed to the screen.</param> /// <param name="printTextDelegate">The function that will actually print the message to the screen</param> /// <param name="printFormattedTextDelegate">Used for recursive declaration of text formatting/styles.</param> public static void PrintMessageWithTime(string message, PrintTextDelegate printTextDelegate, PrintFormattedTextDelegate printFormattedTextDelegate) { // Call our passed in delegate with message. printFormattedTextDelegate(GetCurrentTime() + message, printTextDelegate); }
/// <summary> /// Writes a message to the center of the screen, accepts a delegate object, /// redirecting execution to the appropriate method for printing the text /// in an appropriate colour. /// </summary> /// <param name="message">The message to be printed to the screen.</param> /// <param name="printTextDelegate">The function that will actually print the message to the screen</param> /// <param name="printFormattedTextDelegate">Used for recursive declaration of text formatting/styles.</param> public static void PrintMessageCenter(string message, PrintTextDelegate printTextDelegate, PrintFormattedTextDelegate printFormattedTextDelegate) { // Obtain the left side/left edge of the text we are going to write. int consolePointer = (Console.WindowWidth - message.Length) / 2; // Check/resolve text overflow possibilities. if (consolePointer < 0) { consolePointer = 0; } // Set the cursor position to our new left edge. Console.SetCursorPosition(consolePointer, Console.CursorTop); // Call our delegate to print the message. printFormattedTextDelegate(message, printTextDelegate); // Restore the left side/left edge pointer position. Console.SetCursorPosition(0, Console.CursorTop); }