TOML Syntax Highlighting

The AnsiConsoleTomlExtensions class provides extension methods for writing TOML content to the console with syntax highlighting.

Methods

WriteTomlAsync (Stream, default styles)

Writes TOML content from a stream to the console with default styling asynchronously.

Task<string> WriteTomlAsync(this IAnsiConsole ansiConsole, Stream stream)

Parameters:

Returns: The TOML content as a string.

WriteTomlAsync (Stream, custom styles)

Writes TOML content from a stream to the console with custom styling asynchronously.

Task<string> WriteTomlAsync(this IAnsiConsole ansiConsole, Stream stream, TomlStyles tomlStyles)

Parameters:

Returns: The TOML content as a string.

WriteToml (Stream, default styles)

Writes TOML content from a stream to the console with default styling synchronously.

string WriteToml(this IAnsiConsole ansiConsole, Stream stream)

Parameters:

Returns: The TOML content as a string.

WriteToml (Stream, custom styles)

Writes TOML content from a stream to the console with custom styling synchronously.

string WriteToml(this IAnsiConsole ansiConsole, Stream stream, TomlStyles tomlStyles)

Parameters:

Returns: The TOML content as a string.

WriteToml (string, default styles)

Writes TOML content from a string to the console with default styling.

void WriteToml(this IAnsiConsole ansiConsole, string value)

Parameters:

WriteToml (string, custom styles)

Writes TOML content from a string to the console with custom styling.

void WriteToml(this IAnsiConsole ansiConsole, string value, TomlStyles tomlStyles)

Parameters:

Example Usage

Basic Usage with String

using Spectre.Console;
using NTokenizers.Extensions.Spectre.Console;

var tomlString = """
    # This is a TOML document

    title = "TOML Example"

    [owner]
    name = "Tom Preston-Werner"
    dob = 1979-05-27T07:32:00-08:00

    [database]
    enabled = true
    ports = [ 8001, 8001, 8002 ]
    data = [ ["delta", "phi"], [3.14] ]
    temp_targets = { cpu = 79.5, case = 72.0 }
    """;

AnsiConsole.Console.WriteToml(tomlString);

Custom Styles

using Spectre.Console;
using NTokenizers.Extensions.Spectre.Console;
using NTokenizers.Extensions.Spectre.Console.Styles;

var customTomlStyles = TomlStyles.Default;
customTomlStyles.Identifier = new Style(Color.Orange1);

AnsiConsole.Console.WriteToml(tomlString, customTomlStyles);

Async with Stream

using Spectre.Console;
using NTokenizers.Extensions.Spectre.Console;

await AnsiConsole.Console.WriteTomlAsync(stream);