Write long lines of readable text to the console window with ease

Old Problem…

When writing sentences to a console window, by default, the text will wrap at the exact width of the current window. Unless your sentences happen to consistently have word boundaries at exactly the same intervals as the window width, your text will wrap right in the middle words:

Bad Wrap

New Solution…

A while back, I created a small library that simplifies the syntax for writing messages to a console window called FluentConsole. It allows you to go from this:

Console.WriteLine("This is a string!");

To this:

"This is a string!".WriteLine();

And now, as of version 1.0.39 FluentConsole will automatically wrap long text strings by space-delimited word boundaries. By default, lines are wrapped according to the BufferWidth of the current console window, but you can set the wrap width to any value. In the example below, the first sentence is wrapped at 25 characters while the second sentence is wrapped using the default 80 characters. The final sentence has line wrapping disabled altogether.

Line Wrap Example

Setting this behavior is easy and can be changed in code at anytime, although I image that the default settings will suffice for the vast majority of applications.

var longString = "This is a really long string...";

FluentConsoleSettings.LineWrapOption = LineWrapOption.Manual;
FluentConsoleSettings.LineWrapWidth = 25;

FluentConsoleSettings.LineWrapOption = LineWrapOption.Auto;

FluentConsoleSettings.LineWrapOption = LineWrapOption.Off;

For more information on FluentConsole, check out its GitHub page. To use it in your application, either search for “FluentConsole” in Visual Studio’s NuGet package manager GUI or run the following command from the Package Manager Console:

Install-Package FluentConsole.Library