Skills2026年5月12日·1 分钟阅读

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.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Spectre.Console
通用 CLI 安装命令
npx tokrepo install 12b20719-4dfd-11f1-9bc6-00163e2b0d79

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产