Kotlin Syntax Highlighting

The AnsiConsoleKotlinExtensions class provides extension methods for IAnsiConsole to render Kotlin code with syntax highlighting.

Methods

WriteKotlinAsync (Stream, default styles)

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

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

Parameters:

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

WriteKotlinAsync (Stream, custom styles)

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

Task<string> WriteKotlinAsync(this IAnsiConsole ansiConsole, Stream stream, KotlinStyles kotlinStyles)

Parameters:

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

WriteKotlin (Stream, default styles)

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

string WriteKotlin(this IAnsiConsole ansiConsole, Stream stream)

Parameters:

Returns: The parsed string.

WriteKotlin (Stream, custom styles)

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

string WriteKotlin(this IAnsiConsole ansiConsole, Stream stream, KotlinStyles kotlinStyles)

Parameters:

Returns: The parsed string.

WriteKotlin (string, default styles)

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

void WriteKotlin(this IAnsiConsole ansiConsole, string value)

Parameters:

WriteKotlin (string, custom styles)

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

void WriteKotlin(this IAnsiConsole ansiConsole, string value, KotlinStyles kotlinStyles)

Parameters:

Example Usage

Basic Usage with String

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

var kotlinCode = @"
fun main() {
    println(""Hello, World!"")
}
";

AnsiConsole.Console.WriteKotlin(kotlinCode);

Custom Styles

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

var customKotlinStyles = KotlinStyles.Default;
customKotlinStyles.Keyword = new Style(Color.Orange1);

AnsiConsole.Console.WriteKotlin(kotlinCode, customKotlinStyles);

Async with Stream

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

await AnsiConsole.Console.WriteKotlinAsync(stream);