Chalk for dot net core

Filed under: .NET

The NodeJs ecosystem has a really awesome library for styling console/terminal output called chalk. Chalk improves styling for virtual consoles such as ConEmu, Cmder, or the new hotness: FluentTerminal. The one thing chalk can’t do is improve the Windows Console, it does, however, leverage libuv for extended color support on windows.

I recently built a console app for encrypting files. There were a couple of issues with building it. Console argument parser libraries for .NET aren’t great and I couldn’t find a decent chalk equivalent for .NET. What I did find was that Microsoft added true color to the console in Windows 10 1511.

This has been around for at least two years and I’ve never noticed. I did come around the UTF-8 update post, console color tool, and the new pipeline post. IMHO, These are massive changes for the Windows ecosystem that are flying under the radar. The DotNet CLI could learn from git about colorizing its output.

To my knowledge, these changes have not made their way to .NET Core, but the settings required to enable the new virtual terminal for windows can be invoked through DLLImports in .NET. I can’t believe true color for the console has been around for two years; yet, .NET does not have a chalk port. Maybe I couldn’t find it? ?

Unable to resist the urge that an easy way to style output for the console on Windows was almost in my grasp: I put together a preliminary port of chalk for .NET and have released it as a NuGet package. The source code can be found on gitlab or github

ChalkConsole.WriteLine("test test", Color.Red);

Console.WriteLine(Chalk.Red().Draw("This is a test"));
Console.WriteLine(Chalk.BrightRed().Draw("This is a test"));
Console.WriteLine(Chalk.Color("Orange").Draw("orange you glad Microsoft is updating the console?"));
Console.WriteLine(Chalk.Rgb(255, 0, 0).Draw("Rgb accepted"));
Console.WriteLine(Chalk.BgRed().White().Draw("This is a test"));
Console.WriteLine(Chalk.Magenta().Draw("This is a test w/o bold"));
Console.WriteLine(Chalk.Magenta().Bold().Draw("This is a test"));
Console.WriteLine(Chalk.BrightYellow().Draw("This is a test w bright"));
Console.WriteLine(Chalk.Yellow().Draw("This is a test w/o bright"));
Console.WriteLine(Chalk.Yellow().Dim().Draw("This is a test w  dim"));

// sets the background to purple. 
Console.WriteLine(Chalk.Color("Purple", true).Bold().White().Underline().Draw(" > Woah! "));
Console.WriteLine("Back to being a normie");
Console.WriteLine(Chalk.Grey("chill"));
Console.WriteLine(Chalk.Black("chill"));

// emojis still do not render on windows.
Console.WriteLine(Chalk.StrikeOut().Draw("3 strikes ?"));


Orange you glad Microsoft is updating the console?

Nerdy Mishka