mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 05:18:16 +08:00
Add JSON text renderer (#1086)
* Add JsonText widget to render highlighted JSON Closes #1051
This commit is contained in:
16
examples/Console/Json/Json.csproj
Normal file
16
examples/Console/Json/Json.csproj
Normal 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>
|
36
examples/Console/Json/Program.cs
Normal file
36
examples/Console/Json/Program.cs
Normal 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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user