XConsole 1.4.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package XConsole --version 1.4.2                
NuGet\Install-Package XConsole -Version 1.4.2                
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="XConsole" Version="1.4.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XConsole --version 1.4.2                
#r "nuget: XConsole, 1.4.2"                
#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 XConsole as a Cake Addin
#addin nuget:?package=XConsole&version=1.4.2

// Install XConsole as a Cake Tool
#tool nuget:?package=XConsole&version=1.4.2                

XConsole

NuGet package MIT license NuGet downloads

Extended .NET console with coloring microsyntax, multiline pinning, write-to-position & most useful utils. It’s designed with a focus on performance for professional use in complex tasks: a huge number of asynchronous logs, with the need to highlight important and pin summary data. XConsole is safe for multitasking, safe for console buffer overflows (9000+ lines), very easy to use.

The main features are shown in the following image:

XConsole summary <br><br>

<a name="install"></a>Install

By Package Manager or by adding package reference to *.csproj file:

PM> Install-Package XConsole
<PackageReference Include="XConsole" Version="1.4.*" />

More ways to install see on NuGet Gallery. <br><br><br>

<a name="setup"></a>Setup

Simple way to start using the XConsole is by adding using to your code. After that you can write Console as usual and get all the features of XConsole. Alternatively, you can upgrade an entire project to XConsole at once by adding the following lines to the *.csproj file.

// Safely upgrade a single code file to XConsole
using Console = Chubrik.XConsole.XConsole;
<ItemGroup>
  
  <Using Include="Chubrik.XConsole.XConsole" Alias="Console" />
</ItemGroup>

This trick is great for upgrading an existing regular console application because XConsole is backwards compatible with the standard Console. After the upgrade, the application will not change how it works unless you want to start using the XConsole features. <br><br><br><br>

<a name="coloring"></a>Coloring

Standard console colors

To colorize the text with standard console colors you need to add a prefix to a string. The prefix consists of one or two letters denoting colors, followed by a trailing ` character, after which the text immediately begins. Let’s denote the text color letter as T and the background color letter as B. In this case, there are three prefix patterns: T` to change only text color, TB` to change text and background colors,  B` (space at the beginning) to change only background color. To make a multicolor message split it to parts with individual color prefixes and pass them to single WriteLine method. Be sure that your messages will not be broken by other threads.

Console.WriteLine("G`This line is colorized using simple microsyntax");                 // Single color
Console.WriteLine("C`It is easy ", "Wb`to use many", "R` colors in ", "Y`one message"); // Multicolor

XConsole single color

The following table shows all standard console colors and their letter designations:

XConsole colors table <br>

Extended colors

If you’re running your application on Windows 10+ with .NET 5+, extended colors are available to you:

// Different ways to colorize text the same orange color
Console.WriteLine("This is orange text".Color(Color.Orange)); // Color structure
Console.WriteLine("This is orange text".Color(255, 165, 0));  // Red, green & blue
Console.WriteLine("This is orange text".Color(0xFFA500));     // Hexadecimal number
Console.WriteLine("This is orange text".Color("#FFA500"));    // Hexadecimal string

// Combinations of text and background colors
Console.WriteLine("This is orange with an indigo background.".Color(Color.Orange).BgColor(Color.Indigo));
Console.WriteLine(("This is lime " + "with a brown".BgColor(Color.Brown) + " background.").Color(Color.Lime));
Console.WriteLine($"This is aqua {"with a navy".BgColor(Color.Navy)} background.".Color(Color.Aqua));

XConsole colors extended

NO_COLOR

XConsole supports the NO_COLOR standard with an environment variable and with a property.

Console.NO_COLOR = true; // Disable all colors

<br><br>

<a name="pinning"></a>Pinning

You can pin some text below regular log messages with the Pin method. Pinned text can be static or dynamic, contain one or more lines, and of course can be colorized. Pin is resistant to line wrapping and to console buffer overflows (9000+ log lines).

Static pin

Console.Pin("Simple static pin");           // Simple static pin
Console.Pin("Y`Multicolor", " static pin"); // Multicolor static pin
Console.Pin("Multiline\nstatic pin");       // Multiline static pin

XConsole pin 1 XConsole pin 2 XConsole pin 3

Dynamic pin

Console.Pin(() => "Simple pin, value=" + value);                           // Simple dynamic pin
Console.Pin(() => new[] { "Y`Multicolor", " pin, value=", "C`" + value }); // Multicolor dynamic pin
Console.Pin(() => new[] { "Multiline pin,\nvalue=", "C`" + value });       // Multiline dynamic pin

XConsole pin 4 XConsole pin 5 XConsole pin 6

The dynamic pin will be automatically updated every time the Write or WriteLine methods are called. You can also update a dynamic pin manually using the UpdatePin method. To remove a pin, call the Unpin method.

Console.UpdatePin(); // Update dynamic pin manually
Console.Unpin();     // Remove pin

<br><br>

<a name="positioning"></a>Positioning

XConsole provides a ConsolePosition structure, which is a position in the console area. This is an important feature if you have a lot of log messages. This structure is resistant to console buffer overflows (9000+ log lines) and always points to the correct position in the console area. Each Write and WriteLine method returns a start and end position. You can save them and use later to rewrite the text or add text to the end of the message. To do this, ConsolePosition has its own Write method, which returns a new end position.

NB! The end position of WriteLine means the position after the last character before the line break.

var (begin, end) = Console.WriteLine("Hello, World!"); // Write message and save positions

begin.Write("C`HELLO");       // Rewrite part of text
end = end.Write(" I'm here"); // Add text to the end and update end position
end.Write("Y`!");

XConsole positioning <br><br> You can also get or set the cursor position using the CursorPosition property:

ConsolePosition position = Console.CursorPosition;              // Get cursor position
Console.CursorPosition = new ConsolePosition(left: 15, top: 5); // Set cursor position

<br><br>

<a name="readline"></a>ReadLine

ReadLine has two additional modes for secure input: masked and hidden. Mask symbol is customizable.

Console.ReadLine(ConsoleReadLineMode.Masked);                // Masked ReadLine
Console.ReadLine(ConsoleReadLineMode.Masked, maskChar: '#'); // Masked ReadLine with custom mask
Console.ReadLine(ConsoleReadLineMode.Hidden);                // Hidden ReadLine

XConsole positioning <br><br><br>

<a name="license"></a>License

The XConsole is licensed under the MIT license. <br><br>

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 was computed.  net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on XConsole:

Package Downloads
Chubrik.Kit

Small engine for various projects. Has advanced diagnostics and the most useful features.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 198 8/14/2024
1.4.11 76 7/30/2024
1.4.10 391 11/22/2023
1.4.9 441 8/20/2023
1.4.8 447 7/29/2023
1.4.7 662 4/7/2023
1.4.5 498 3/28/2023
1.4.4 559 1/29/2023
1.4.3 670 11/25/2022
1.4.2 592 11/9/2022
1.4.1 643 11/8/2022
1.4.0 650 11/5/2022
1.3.2 656 11/4/2022
1.3.1 662 10/30/2022
1.3.0 698 10/24/2022
1.2.3 697 10/22/2022
1.2.2 740 10/19/2022
1.2.1 656 10/17/2022
1.2.0 717 9/16/2022
1.1.6 865 9/16/2022
1.1.5 696 7/17/2022
1.1.4 723 5/12/2022
1.1.3 660 5/1/2022
1.1.2 682 4/29/2022
1.1.1 668 4/27/2022
1.1.0 634 4/27/2022
1.0.6 760 4/26/2022
1.0.5 794 4/21/2022
1.0.4 770 4/20/2022
1.0.3 737 4/14/2022
1.0.2 797 4/9/2022
1.0.1 762 3/30/2022
1.0.0 773 3/27/2022