C Syntax Highlighting

The AnsiConsoleCExtensions class provides extension methods for IAnsiConsole to render C code with syntax highlighting.

Methods

WriteCAsync (Stream, default styles)

Writes C code from a stream to the console with default syntax highlighting asynchronously.

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

Parameters:

Returns: A task representing the asynchronous operation with the parsed string.

WriteCAsync (Stream, custom styles)

Writes C code from a stream to the console with custom syntax highlighting asynchronously.

Task<string> WriteCAsync(this IAnsiConsole ansiConsole, Stream stream, CStyles cStyles)

Parameters:

Returns: A task representing the asynchronous operation with the parsed string.

WriteC (Stream, default styles)

Writes C code from a stream to the console with default syntax highlighting synchronously.

string WriteC(this IAnsiConsole ansiConsole, Stream stream)

Parameters:

Returns: The parsed string.

WriteC (Stream, custom styles)

Writes C code from a stream to the console with custom syntax highlighting synchronously.

string WriteC(this IAnsiConsole ansiConsole, Stream stream, CStyles cStyles)

Parameters:

Returns: The parsed string.

WriteC (string, default styles)

Writes C code from a string to the console with default syntax highlighting.

void WriteC(this IAnsiConsole ansiConsole, string value)

Parameters:

WriteC (string, custom styles)

Writes C code from a string to the console with custom syntax highlighting.

void WriteC(this IAnsiConsole ansiConsole, string value, CStyles cStyles)

Parameters:

Example Usage

Basic Usage with String

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

var cCode = """
    #include <stdio.h>

    // Hello World in C
    int main() {
        printf("Hello, World!\n");
        return 0;
    }
    """;

AnsiConsole.Console.WriteC(cCode);

Custom Styles

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

var customCStyles = CStyles.Default;
customCStyles.Keyword = new Style(Color.Orange1);

AnsiConsole.Console.WriteC(cCode, customCStyles);

Async with Stream

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

await AnsiConsole.Console.WriteCAsync(stream);