Spectre.Console lets you make beautiful console apps with .NET Core
I've long said, as a fan of the console and text mode, that the command line is underloved. You can do accelerated 3D VR, sure, but impress me with a nice ASCII progress bar or spinner and oh my! *Chef's kiss*
Enter yet another lovely Console library in the form of Spectre.Console. You may know Patrik Svensson as the creator of the wonderful Cake build system. He is also enhancing our consoles with Spectre.Console. It even has support for Figlet! What's FIGlet you say?!? Well, it's giant fonts with ASCII, of course!
_____ ___ ____ _ _
| ___|_ _/ ___| | ___| |_
| |_ | | | _| |/ _ \ __|
| _| | | |_| | | __/ |_
|_| |___\____|_|\___|\__|
Not very accessible, to be sure, but super impactful for the sighted. I encourage you to make apps that include everyone.
How cool is to bring such madness to C# and .NET!
var font = FigletFont.Load("starwars.flf");
AnsiConsole.Render(
new FigletText(font, "Hello")
.LeftAligned()
.Color(Color.Red));
That's just the start! Who ever said ASCII/ANSI style tables needed to be hard and ugly? Spectre says nay nay!
You don't need to be fancy if you don't want to. You can just do some ANSI which is supported by nearly every console out there. Just bring in dotnet add package Spectre.Console and
using Spectre.Console
public static class Program
{
public static void Main(string[] args)
{
AnsiConsole.Markup("[underline red]Hello[/] World!");
}
}
You can render calendars!
var calendar = new Calendar(2020,10);
AnsiConsole.Render(calendar);
Giving you
2020 October
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ │ │ │ │ 1 │ 2 │ 3 │
│ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │
│ 11 │ 12 │ 13 │ 14 │ 15 │ 16 │ 17 │
│ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │
│ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │
│ │ │ │ │ │ │ │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
But tables are where Spectre.Console really shines!
There is so much good stuff in there. I wish the .NET command line would use the AnsiConsole.WriteException method, just to make my failures that much prettier!
Regardless, get over to https://github.com/spectresystems/spectre.console and give this team a Star or two. And go make your utilities, your console apps, those little apps that are just gray and sad...go make them awesome!
Sponsor: Need a multi-cluster load balancer and API gateway? Try VoltMesh: built for modern and distributed apps that require automation, performance and visibility. Start for free today.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
Comments are closed.