Add JSON text renderer (#1086)

* Add JsonText widget to render highlighted JSON

Closes #1051
This commit is contained in:
Patrik Svensson
2022-12-31 19:17:15 +01:00
committed by GitHub
parent 3e6e0990c5
commit 54be64ec84
48 changed files with 1634 additions and 21 deletions

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ExampleTitle>Json</ExampleTitle>
<ExampleDescription>Demonstrates how to print syntax highlighted JSON.</ExampleDescription>
<ExampleGroup>Widgets</ExampleGroup>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Shared\Shared.csproj" />
<ProjectReference Include="..\..\..\src\Spectre.Console.Json\Spectre.Console.Json.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,36 @@
using Spectre.Console;
using Spectre.Console.Json;
namespace Json;
public static class Program
{
public static void Main()
{
var json = new JsonText(
"""
{
"hello": 32,
"world": {
"foo": 21,
"bar": 255,
"baz": [
0.32, 0.33e-32,
0.42e32, 0.55e+32,
{
"hello": "world",
"lol": null
}
]
}
}
""");
AnsiConsole.Write(
new Panel(json)
.Header("Some JSON in a panel")
.Collapse()
.RoundedBorder()
.BorderColor(Color.Yellow));
}
}