Skip to main content
Published
Apr 10, 2026
6mo ago
Total Downloads
256
256

Install

dotnet add package Devlooped.Spectre.Yaml --version 1.0.0-alpha
ProductVersions
.NET
net10.0

README

EULA OSS GitHub

Overview

Devlooped.Spectre.Yaml adds a YamlText renderable to Spectre.Console that displays YAML with syntax-highlighted tokens (keys, strings, numbers, booleans, nulls, and comments). It also accepts JSON and arbitrary .NET objects, automatically converting them to YAML before rendering.

Usage

From a YAML string

using Spectre.Console;

AnsiConsole.Write(new YamlText("""
    server:
      host: localhost
      port: 8080
      tls: true
    """));

From a .NET object

using Spectre.Console;

var config = new
{
    Server = new { Host = "localhost", Port = 8080, Tls = true },
    Retries = 3,
    Tags = new[] { "web", "api" },
};

AnsiConsole.Write(new YamlText(config));

System.Text.Json.JsonSerializer serializes the object; the resulting JSON is then converted to YAML. JsonNode and JsonElement overloads are also available.

Inside a Panel

using Spectre.Console;

AnsiConsole.Write(
    new Panel(new YamlText(myObject))
        .Header("Configuration")
        .BorderColor(Color.Yellow)
        .Padding(1, 1));

Customizing colors

Each token type has a configurable Style. Use the fluent extension methods for the most concise syntax:

var text = new YamlText(yaml)
    .KeyColor(Color.Yellow)
    .StringColor(Color.Cyan1)
    .NumberColor(Color.Blue)
    .BooleanColor(Color.Green)
    .NullColor(Color.Grey)
    .CommentColor(Color.DarkSlateGray1);

AnsiConsole.Write(text);

Or assign Style objects directly when you need full control (foreground, background, decorations):

var text = new YamlText(yaml)
{
    KeyStyle    = new Style(Color.Yellow, decoration: Decoration.Bold),
    StringStyle = new Style(Color.Cyan1),
};

Default colors

Token Default
Key Color.Grey
String Color.Red
Number Color.Blue
Boolean Color.Green
Null Color.Grey
Comment Color.Grey + Dim

Open Source Maintenance Fee

To ensure the long-term sustainability of this project, users of this package who generate revenue must pay an Open Source Maintenance Fee. While the source code is freely available under the terms of the License, this package and other aspects of the project require adherence to the Maintenance Fee.

To pay the Maintenance Fee, become a Sponsor at the proper OSMF tier. A single fee covers all of Devlooped packages.

Sponsors

Clarius Org MFB Technologies, Inc. Khamza Davletov SandRock DRIVE.NET, Inc. Keith Pickford Thomas Bolon Kori Francis Reuben Swartz Jacob Foshee Eric Johnson Jonathan Ken Bonny Simon Cropp agileworks-eu Zheyu Shen Vezel ChilliCream 4OTC domischell Adrian Alonso torutek mccaffers Seika Logiciel Andrew Grant Lars prime167

Sponsor this project

Learn more about GitHub Sponsors

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.