Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsMay 12, 2026·3 min de lectura

Spectre.Console — Beautiful Console Output for .NET Applications

A .NET library for building rich, interactive terminal applications with tables, progress bars, trees, and styled text.

Introduction

Spectre.Console is a .NET library that makes it easy to create visually appealing console applications. It provides high-level widgets like tables, trees, bar charts, and progress bars, plus a command-line argument parser, all rendered beautifully in the terminal.

What Spectre.Console Does

  • Renders rich widgets (tables, trees, panels, bar charts) with ANSI color support
  • Provides interactive prompts for text input, selection, and multi-selection
  • Includes a progress display system with multiple concurrent tasks and spinners
  • Ships with a CLI argument parser via Spectre.Console.Cli with dependency injection
  • Handles terminal capability detection and graceful degradation automatically

Architecture Overview

The library operates on a rendering pipeline that converts widget objects into a sequence of ANSI escape codes. Each widget implements an IRenderable interface, producing Segment objects that are composed into the final output. The AnsiConsole static class manages the output stream and detects terminal capabilities (color depth, Unicode support). The CLI parser uses a command pattern with typed settings classes, supporting nested commands and automatic help generation.

Self-Hosting & Configuration

  • Install via NuGet: dotnet add package Spectre.Console
  • For the CLI parser, also add Spectre.Console.Cli
  • Works on Windows Terminal, iTerm2, and any terminal supporting ANSI escape codes
  • Configure color system override with AnsiConsole.Profile.Capabilities
  • Supports .NET 6+ and .NET Standard 2.0 for broad compatibility

Key Features

  • Tables with configurable borders, alignment, padding, and column sizing
  • Live display that updates in place for dashboards and monitoring tools
  • Figlet text rendering for large banner-style headings
  • Exception rendering with syntax-highlighted stack traces
  • Markup language for inline styling: [bold red]Error[/]

Comparison with Similar Tools

  • Rich (Python) — similar concept for Python; Spectre.Console is the .NET equivalent
  • Chalk (.NET) — basic color output; Spectre.Console adds full widget rendering
  • System.Console — built-in .NET class with no formatting; Spectre.Console wraps it with a rich API
  • Terminal.Gui — full TUI framework with windows and dialogs; Spectre.Console focuses on output rendering and prompts

FAQ

Q: Does it work on Windows Command Prompt? A: Yes. It detects capabilities and falls back gracefully when ANSI support is limited.

Q: Can I use it alongside Terminal.Gui? A: They serve different purposes and can coexist, though they should not write to the console simultaneously.

Q: Is there async support for progress bars? A: Yes. The progress display integrates with async/await via AnsiConsole.Progress().StartAsync().

Q: Does the CLI parser support dependency injection? A: Yes. You can register a custom type registrar to integrate with any DI container.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados