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

@ -3,7 +3,7 @@ namespace Spectre.Console;
/// <summary>
/// Contains extension methods for <see cref="char"/>.
/// </summary>
public static class CharExtensions
public static partial class CharExtensions
{
/// <summary>
/// Gets the cell width of a character.

View File

@ -0,0 +1,9 @@
namespace Spectre.Console.Internal;
internal static partial class CharExtensions
{
public static bool IsDigit(this char character, int min = 0)
{
return char.IsDigit(character) && character >= (char)min;
}
}

View File

@ -118,7 +118,7 @@ internal static class EnumerableExtensions
}
#endif
public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(
public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> ZipThree<TFirst, TSecond, TThird>(
this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third)
{
return first.Zip(second, (a, b) => (a, b))

View File

@ -89,7 +89,7 @@ internal static class Ratio
var totalRemaining = total;
var result = new List<int>();
foreach (var (ratio, maximum, value) in ratios.Zip(maximums, values))
foreach (var (ratio, maximum, value) in ratios.ZipThree(maximums, values))
{
if (ratio != 0 && totalRatio > 0)
{

View File

@ -23,11 +23,22 @@ internal sealed class StringBuffer : IDisposable
_reader.Dispose();
}
public char Expect(char character)
{
var read = Read();
if (read != character)
{
throw new InvalidOperationException($"Expected '{character}', but found '{read}'");
}
return read;
}
public char Peek()
{
if (Eof)
{
throw new InvalidOperationException("Tried to peek past the end of the text.");
return '\0';
}
return (char)_reader.Peek();
@ -37,7 +48,7 @@ internal sealed class StringBuffer : IDisposable
{
if (Eof)
{
throw new InvalidOperationException("Tried to read past the end of the text.");
return '\0';
}
Position++;

View File

@ -36,6 +36,10 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Widgets\Json\" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants)TRACE;WCWIDTH_VISIBILITY_INTERNAL</DefineConstants>
</PropertyGroup>