mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00
Add JSON text renderer (#1086)
* Add JsonText widget to render highlighted JSON Closes #1051
This commit is contained in:
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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))
|
@ -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)
|
||||
{
|
||||
|
@ -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++;
|
||||
|
@ -36,6 +36,10 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Widgets\Json\" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DefineConstants>$(DefineConstants)TRACE;WCWIDTH_VISIBILITY_INTERNAL</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
Reference in New Issue
Block a user