Swift Syntax Highlighting

The AnsiConsoleSwiftExtensions class provides extension methods for IAnsiConsole to render Swift code with syntax highlighting.

Methods

WriteSwiftAsync (Stream, default styles)

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

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

Parameters:

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

WriteSwiftAsync (Stream, custom styles)

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

Task<string> WriteSwiftAsync(this IAnsiConsole ansiConsole, Stream stream, SwiftStyles swiftStyles)

Parameters:

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

WriteSwift (Stream, default styles)

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

string WriteSwift(this IAnsiConsole ansiConsole, Stream stream)

Parameters:

Returns: The parsed string.

WriteSwift (Stream, custom styles)

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

string WriteSwift(this IAnsiConsole ansiConsole, Stream stream, SwiftStyles swiftStyles)

Parameters:

Returns: The parsed string.

WriteSwift (string, default styles)

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

void WriteSwift(this IAnsiConsole ansiConsole, string value)

Parameters:

WriteSwift (string, custom styles)

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

void WriteSwift(this IAnsiConsole ansiConsole, string value, SwiftStyles swiftStyles)

Parameters:

Example Usage

Basic Usage with String

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

var swiftCode = @"
import Foundation

print(""Hello, World!"")
";

AnsiConsole.Console.WriteSwift(swiftCode);

Custom Styles

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

var customSwiftStyles = SwiftStyles.Default;
customSwiftStyles.Keyword = new Style(Color.Orange1);

AnsiConsole.Console.WriteSwift(swiftCode, customSwiftStyles);

Async with Stream

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

await AnsiConsole.Console.WriteSwiftAsync(stream);