Woof.Console 6.2.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Woof.Console --version 6.2.0                
NuGet\Install-Package Woof.Console -Version 6.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Woof.Console" Version="6.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Woof.Console --version 6.2.0                
#r "nuget: Woof.Console, 6.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Woof.Console as a Cake Addin
#addin nuget:?package=Woof.Console&version=6.2.0

// Install Woof.Console as a Cake Tool
#tool nuget:?package=Woof.Console&version=6.2.0                

Woof.Console

A part of the Woof Tookit by CodeDog.

Distributed under MIT License. (c)2022 by CodeDog, All rights reserved.


About

Console extensions and filters allowing colored output and using multiple cursors for advanced layouts.

Using the Console class for displaying colored text, updating text that is already displayed is tedious. It requires a lot of code and repetitions.

Also, configuring the console output correctly for both Windows and Linux terminal is not trivial.

The package takes care of the proper terminal configuration and allows to use full potential of the console output with absolute minimal effort.

Just see the demo.

Usage

To initialize the extended console with the default settings just use:

ConsoleEx.Init();

This will enable the colored output and set the UTF-8 encoding.

Now to output colored text, just use the special hex-codes. If you're familiar with HTML and CSS colors, the hex-codes are just a type of 3 characters hexadecimal codes designed to be as close to the RGB representation as possible. So f00 is bright red, 0f0 is bright green, 00f is bright blue, 777 is gray, fff is white, 000 is black and so on. An optional fourth character b means the color should be set as the background color.

Here's an example making the word "red" red:

Console.WriteLine("The word `f00`red` should be red.");

Here's an example making the word "red" inverse red:

Console.WriteLine("The word `000``f00b`red` should be red.");

OK, it can actually be pink-ish. Never mind.

Use the first '`' character to start the hex-code. Then goes the hex-code, then use the next '`' character to end the hex-code. The following text will be in selected color, until the next '`' character is outputed. Then the text color will be reset to the default value.

The way to achieve the same effect without Woof.Console would be like:

Console.Write("The word ");
var foreground = Console.ForegroundColor;
var background = Console.BackgroundColor;
Console.ForegroundColor = ConsoleColor.Black;
Console.BackgroundColor = ConsoleColor.Red;
Console.Write("red");
Console.ForegroundColor = foreground;
Console.BackgroundColor = background;
Console.WriteLine(" should be red.");

Just for the last example.

There's another neat feature, the Cursor. It's basically a kind of a bookmark storing a console cursor position. You can mark a place with it, and then output some text there later. What's important, placing the text on the cursor position will not affect the main cursor position.

It's mostly used by ConsoleEx.Start() method, that displays a "starting" message and returns the cursor pointing to the end of the text. Then you can start something asynchronous and display the result right at the cursor position.

The example without Woof.Console would be even longer, so... Just see how it's used in the demo.

The package has also some other cool features, like hex-data dump, of course, in color. See the demo.

OK, but what about if the terminal doesn't support the colored output? Well, that would be weird, but in such case the color codes will just be ignored. See the demo.

But how does it work? See the source. It's not rocket science. For full list of the color hex-codes, yes, see the demo.


Disclaimer

Woof Toolkit is a work in progress in constant development, however it's carefully maintained with production code quality.

PLEASE report all issues on GitHub!

Describe how to reproduce an issue. Also feel free to suggest new features or improvements.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Woof.Console:

Package Downloads
Woof.Service

Windows Service made easy.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.0.0 173 8/6/2023
6.2.0 461 2/20/2022
6.0.0 328 11/9/2021
5.2.1 313 9/8/2021
5.2.0 316 9/8/2021
5.1.0 303 9/8/2021
5.0.1 302 9/7/2021
5.0.0 297 9/7/2021
2.2.0 503 9/9/2020
2.1.2 448 9/8/2020
2.1.1 511 9/8/2020
2.1.0 551 9/8/2020
2.0.1 612 9/26/2019
2.0.0 1,209 7/25/2019

Woof Toolkit 6.2 first release.