Skip to content

CustomConsole WriteText

Iuga Alexandru edited this page Jan 7, 2018 · 5 revisions

Description

A number of static methods that helps writing text to the console.

Features

  • Normal, Warning, Error and Emphasised text - Specialized methods to write predefined types of text: Normal, Warning, Error and Emphasised.
  • custom foreground and background colors - Can specify a custom foreground and background colors.
  • Write or WriteLine - The methods come in pairs. One to just write the text and another one to write also the line terminator at the end.
  • Horizontal Alignment - The text can be aligned (left, center, right) relative to the ConsoleBuffer size.

Example

Colors Example

CustomConsole.WriteLine("Normal: This is a normal line of text.");
CustomConsole.WriteLine();
CustomConsole.WriteLineEmphasies("Emphasies: But I can also write an emphasized text.");
CustomConsole.WriteLine();
CustomConsole.WriteLineSuccess("Success: And everything is ok if it finishes well :)");
CustomConsole.WriteLine();
CustomConsole.WriteLineWarning("Warning: But I have to warn you about the consequences of something not being done correctly.");
CustomConsole.WriteLine();
CustomConsole.WriteLineError("Error: If some error occures and the application will crush with an exception, I will display it on the screen immediately.");

Result:

Alignment Example

CustomConsole.WriteLine(HorizontalAlignment.Left, "This is a text aligned to left.");
CustomConsole.WriteLine(HorizontalAlignment.Left, "This is anoter text aligned to left.");
CustomConsole.WriteLine();
CustomConsole.WriteLine(HorizontalAlignment.Center, "This is a text aligned to center.");
CustomConsole.WriteLine(HorizontalAlignment.Center, "This is another text aligned to center.");
CustomConsole.WriteLine();
CustomConsole.WriteLine(HorizontalAlignment.Right, "This is a text aligned to right.");
CustomConsole.WriteLine(HorizontalAlignment.Right, "This is another text aligned to right.");

Result:

Clone this wiki locally