Spectre.Console for C# (.NET): Complete Guide with Examples

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Spectre.Console for C# (.NET): Complete Guide

\n\n

Spectre.Console is a powerful library for .NET that turns ordinary console output into something visually appealing and interactive. It allows C# developers to create beautiful, structured, and informative command-line interfaces (CLI) with minimal effort. Instead of boring monochrome text, you get support for colors, tables, trees, progress bars, charts, and even interactive prompts.

\n\n

Why do you need Spectre.Console? In modern development, console applications are often used for DevOps tools, automation scripts, data analysis, and utilities. Users expect not only functionality but also convenience. Spectre.Console solves the problem of "bare" output, making logs understandable and interaction with the application pleasant. It is especially useful for creating professional CLI tools where readability and visual hierarchy of data are important.

\n\n

The library is built on the principles of composition and provides a rich set of "widgets" that can be combined. It is actively supported by the community, has detailed documentation, and is used in major projects such as Cake Build, NuGet Client, and .NET SDK. If you write in C# and want your console utility to look like a modern tool, not a relic from the 80s — Spectre.Console is your choice.

\n\n

Installation

\n

Spectre.Console is distributed via NuGet. To install, run one of the following commands in the terminal or Package Manager Console:

\n\n
# Via .NET CLI\ndotnet add package Spectre.Console\n\n# Via Package Manager Console (Visual Studio)\nInstall-Package Spectre.Console\n\n# Or via NuGet Package Manager in your IDE\n
\n\n

After installation, add using Spectre.Console; at the top of your code file.

\n\n

Quick Start

\n

A minimal working example demonstrating the main features:

\n\n
using Spectre.Console;\n\n// Simple colored message\nAnsiConsole.MarkupLine("[bold green]Hello, Spectre.Console![/]");\n\n// Table\nvar table = new Table();\ntable.AddColumn("Name");\ntable.AddColumn("Age");\ntable.AddRow("Alice", "30");\ntable.AddRow("Bob", "25");\nAnsiConsole.Write(table);\n\n// Progress bar\nAnsiConsole.Progress()\n    .Start(ctx =>\n    {\n        var task = ctx.AddTask("[yellow]Processing...[/]");\n        while (!task.IsFinished)\n        {\n            task.Increment(15);\n            Thread.Sleep(200);\n        }\n    });\n
\n\n

This code will output a colored greeting, a table with data, and an animated progress bar.

\n\n

Main Methods, Functions, and Classes

\n\n

1. AnsiConsole.MarkupLine

\n

Signature: public static void MarkupLine(string markup)

\n

What it does: Outputs a string with markup support for text styling (colors, styles, links).

\n
AnsiConsole.MarkupLine("[bold yellow]Warning![/] [red]Error[/] on line [underline]42[/].");\n
\n\n

2. AnsiConsole.Progress

\n

Signature: public static Progress Display(ProgressContext context) (via fluent API)

\n

What it does: Creates and displays an interactive progress bar with the ability to add multiple tasks.

\n
AnsiConsole.Progress()\n    .Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())\n    .Start(ctx =>\n    {\n        var task1 = ctx.AddTask("[green]Downloading file 1[/]");\n        var task2 = ctx.AddTask("[blue]Downloading file 2[/]");\n        while (!task1.IsFinished || !task2.IsFinished)\n        {\n            task1.Increment(5);\n            task2.Increment(3);\n            Thread.Sleep(100);\n        }\n    });\n
\n\n

3. Ta

Recommendations