|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: "Toml" |
| 4 | +--- |
| 5 | + |
| 6 | +# TOML Syntax Highlighting |
| 7 | + |
| 8 | +The `AnsiConsoleTomlExtensions` class provides extension methods for writing TOML content to the console with syntax highlighting. |
| 9 | + |
| 10 | +## Methods |
| 11 | + |
| 12 | +### WriteTomlAsync (Stream, default styles) |
| 13 | + |
| 14 | +Writes TOML content from a stream to the console with default styling asynchronously. |
| 15 | + |
| 16 | +```csharp |
| 17 | +Task<string> WriteTomlAsync(this IAnsiConsole ansiConsole, Stream stream) |
| 18 | +``` |
| 19 | + |
| 20 | +**Parameters:** |
| 21 | +- `ansiConsole`: The console to write to. |
| 22 | +- `stream`: The stream containing TOML content. |
| 23 | + |
| 24 | +**Returns:** The TOML content as a string. |
| 25 | + |
| 26 | +### WriteTomlAsync (Stream, custom styles) |
| 27 | + |
| 28 | +Writes TOML content from a stream to the console with custom styling asynchronously. |
| 29 | + |
| 30 | +```csharp |
| 31 | +Task<string> WriteTomlAsync(this IAnsiConsole ansiConsole, Stream stream, TomlStyles tomlStyles) |
| 32 | +``` |
| 33 | + |
| 34 | +**Parameters:** |
| 35 | +- `ansiConsole`: The console to write to. |
| 36 | +- `stream`: The stream containing TOML content. |
| 37 | +- `tomlStyles`: The styles to use for TOML token coloring. |
| 38 | + |
| 39 | +**Returns:** The TOML content as a string. |
| 40 | + |
| 41 | +### WriteToml (Stream, default styles) |
| 42 | + |
| 43 | +Writes TOML content from a stream to the console with default styling synchronously. |
| 44 | + |
| 45 | +```csharp |
| 46 | +string WriteToml(this IAnsiConsole ansiConsole, Stream stream) |
| 47 | +``` |
| 48 | + |
| 49 | +**Parameters:** |
| 50 | +- `ansiConsole`: The console to write to. |
| 51 | +- `stream`: The stream containing TOML content. |
| 52 | + |
| 53 | +**Returns:** The TOML content as a string. |
| 54 | + |
| 55 | +### WriteToml (Stream, custom styles) |
| 56 | + |
| 57 | +Writes TOML content from a stream to the console with custom styling synchronously. |
| 58 | + |
| 59 | +```csharp |
| 60 | +string WriteToml(this IAnsiConsole ansiConsole, Stream stream, TomlStyles tomlStyles) |
| 61 | +``` |
| 62 | + |
| 63 | +**Parameters:** |
| 64 | +- `ansiConsole`: The console to write to. |
| 65 | +- `stream`: The stream containing TOML content. |
| 66 | +- `tomlStyles`: The styles to use for TOML token coloring. |
| 67 | + |
| 68 | +**Returns:** The TOML content as a string. |
| 69 | + |
| 70 | +### WriteToml (string, default styles) |
| 71 | + |
| 72 | +Writes TOML content from a string to the console with default styling. |
| 73 | + |
| 74 | +```csharp |
| 75 | +void WriteToml(this IAnsiConsole ansiConsole, string value) |
| 76 | +``` |
| 77 | + |
| 78 | +**Parameters:** |
| 79 | +- `ansiConsole`: The console to write to. |
| 80 | +- `value`: The TOML string to write. |
| 81 | + |
| 82 | +### WriteToml (string, custom styles) |
| 83 | + |
| 84 | +Writes TOML content from a string to the console with custom styling. |
| 85 | + |
| 86 | +```csharp |
| 87 | +void WriteToml(this IAnsiConsole ansiConsole, string value, TomlStyles tomlStyles) |
| 88 | +``` |
| 89 | + |
| 90 | +**Parameters:** |
| 91 | +- `ansiConsole`: The console to write to. |
| 92 | +- `value`: The TOML string to write. |
| 93 | +- `tomlStyles`: The styles to use for TOML token coloring. |
| 94 | + |
| 95 | +## Example Usage |
| 96 | + |
| 97 | +### Basic Usage with String |
| 98 | + |
| 99 | +```csharp |
| 100 | +using Spectre.Console; |
| 101 | +using NTokenizers.Extensions.Spectre.Console; |
| 102 | + |
| 103 | +var tomlString = """ |
| 104 | + # This is a TOML document |
| 105 | +
|
| 106 | + title = "TOML Example" |
| 107 | +
|
| 108 | + [owner] |
| 109 | + name = "Tom Preston-Werner" |
| 110 | + dob = 1979-05-27T07:32:00-08:00 |
| 111 | +
|
| 112 | + [database] |
| 113 | + enabled = true |
| 114 | + ports = [ 8001, 8001, 8002 ] |
| 115 | + data = [ ["delta", "phi"], [3.14] ] |
| 116 | + temp_targets = { cpu = 79.5, case = 72.0 } |
| 117 | + """; |
| 118 | + |
| 119 | +AnsiConsole.Console.WriteToml(tomlString); |
| 120 | +``` |
| 121 | + |
| 122 | +### Custom Styles |
| 123 | + |
| 124 | +```csharp |
| 125 | +using Spectre.Console; |
| 126 | +using NTokenizers.Extensions.Spectre.Console; |
| 127 | +using NTokenizers.Extensions.Spectre.Console.Styles; |
| 128 | + |
| 129 | +var customTomlStyles = TomlStyles.Default; |
| 130 | +customTomlStyles.Identifier = new Style(Color.Orange1); |
| 131 | + |
| 132 | +AnsiConsole.Console.WriteToml(tomlString, customTomlStyles); |
| 133 | +``` |
| 134 | + |
| 135 | +### Async with Stream |
| 136 | + |
| 137 | +```csharp |
| 138 | +using Spectre.Console; |
| 139 | +using NTokenizers.Extensions.Spectre.Console; |
| 140 | + |
| 141 | +await AnsiConsole.Console.WriteTomlAsync(stream); |
| 142 | +``` |
0 commit comments