mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 00:42:51 +08:00
Add example infrastructure
* Add "Shared" projects for all examples * Update "Colors" example with better TrueColor demo * Use same namespace for all examples
This commit is contained in:
parent
2fe2bb3c32
commit
3545e0f6b5
@ -1,7 +1,7 @@
|
||||
using System.ComponentModel;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Delegates
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static partial class Program
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
@ -11,7 +11,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Delegates
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static partial class Program
|
||||
{
|
||||
@ -22,7 +21,7 @@ namespace Delegates
|
||||
|
||||
private static int Foo(CommandContext context)
|
||||
{
|
||||
Console.WriteLine("Foo");
|
||||
AnsiConsole.WriteLine("Foo");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -30,7 +29,7 @@ namespace Delegates
|
||||
{
|
||||
for (var index = 0; index < settings.Count; index++)
|
||||
{
|
||||
Console.WriteLine("Bar");
|
||||
AnsiConsole.WriteLine("Bar");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
@ -11,7 +11,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Dynamic
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public sealed class MyCommand : Command
|
||||
{
|
||||
@ -13,7 +13,7 @@ namespace Dynamic
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine("Value = {0}", data);
|
||||
AnsiConsole.WriteLine("Value = {0}", data);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Dynamic
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -2,7 +2,7 @@ using System;
|
||||
using System.ComponentModel;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Injection.Commands
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public sealed class DefaultCommand : Command<DefaultCommand.Settings>
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace Injection
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public interface IGreeter
|
||||
{
|
||||
@ -11,7 +9,7 @@ namespace Injection
|
||||
{
|
||||
public void Greet(string name)
|
||||
{
|
||||
Console.WriteLine($"Hello {name}!");
|
||||
AnsiConsole.WriteLine($"Hello {name}!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Injection
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public sealed class TypeRegistrar : ITypeRegistrar
|
||||
{
|
||||
|
@ -2,7 +2,7 @@ using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Injection
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public sealed class TypeResolver : ITypeResolver, IDisposable
|
||||
{
|
||||
|
@ -15,7 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,8 +1,7 @@
|
||||
using Injection.Commands;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Injection
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
|
@ -1,8 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Spectre.Console;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Logging.Commands
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public class HelloCommand : Command<HelloCommand.Settings>
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using Serilog.Events;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Logging.Commands
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public class LogCommandSettings : CommandSettings
|
||||
{
|
||||
|
@ -1,8 +1,7 @@
|
||||
using Logging.Commands;
|
||||
using Serilog.Core;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Logging
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public class LogInterceptor : ICommandInterceptor
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Serilog.Core;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Logging
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
internal class LoggingEnricher : ILogEventEnricher
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Logging
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public sealed class TypeRegistrar : ITypeRegistrar
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Logging
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public sealed class TypeResolver : ITypeResolver
|
||||
{
|
||||
|
@ -20,7 +20,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,4 +1,3 @@
|
||||
using Logging.Commands;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using Spectre.Console.Cli;
|
||||
@ -13,7 +12,7 @@ using Spectre.Console.Cli;
|
||||
* Spectre.Console CommandInterceptor
|
||||
*/
|
||||
|
||||
namespace Logging
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace BordersExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Calendars
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,8 +9,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console.ImageSharp\Spectre.Console.ImageSharp.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -4,9 +4,8 @@ Licensed under GNU Free Documentation License 1.2
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace CanvasExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Mandelbrot
|
||||
{
|
||||
|
@ -1,10 +1,9 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace CanvasExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Charts
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,27 +1,23 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace ColorExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// No colors
|
||||
/////////////////////////////////////////////////////////////////
|
||||
if (AnsiConsole.Profile.ColorSystem == ColorSystem.NoColors)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// No colors
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
AnsiConsole.WriteLine("No colors are supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 3-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
if (AnsiConsole.Profile.Supports(ColorSystem.Legacy))
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 3-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(new Rule("[yellow bold underline]3-bit Colors[/]").RuleStyle("grey").LeftAligned());
|
||||
@ -30,6 +26,7 @@ namespace ColorExample
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
AnsiConsole.Background = Color.FromInt32(i);
|
||||
AnsiConsole.Foreground = AnsiConsole.Background.GetInvertedColor();
|
||||
AnsiConsole.Write(string.Format(" {0,-9}", AnsiConsole.Background.ToString()));
|
||||
AnsiConsole.ResetColors();
|
||||
if ((i + 1) % 8 == 0)
|
||||
@ -39,12 +36,11 @@ namespace ColorExample
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 4-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
if (AnsiConsole.Profile.Supports(ColorSystem.Standard))
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 4-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(new Rule("[yellow bold underline]4-bit Colors[/]").RuleStyle("grey").LeftAligned());
|
||||
@ -53,6 +49,7 @@ namespace ColorExample
|
||||
for (var i = 0; i < 16; i++)
|
||||
{
|
||||
AnsiConsole.Background = Color.FromInt32(i);
|
||||
AnsiConsole.Foreground = AnsiConsole.Background.GetInvertedColor();
|
||||
AnsiConsole.Write(string.Format(" {0,-9}", AnsiConsole.Background.ToString()));
|
||||
AnsiConsole.ResetColors();
|
||||
if ((i + 1) % 8 == 0)
|
||||
@ -62,12 +59,11 @@ namespace ColorExample
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 8-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
if (AnsiConsole.Profile.Supports(ColorSystem.EightBit))
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 8-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(new Rule("[yellow bold underline]8-bit Colors[/]").RuleStyle("grey").LeftAligned());
|
||||
@ -79,6 +75,7 @@ namespace ColorExample
|
||||
{
|
||||
var number = i * 16 + j;
|
||||
AnsiConsole.Background = Color.FromInt32(number);
|
||||
AnsiConsole.Foreground = AnsiConsole.Background.GetInvertedColor();
|
||||
AnsiConsole.Write(string.Format(" {0,-4}", number));
|
||||
AnsiConsole.ResetColors();
|
||||
if ((number + 1) % 16 == 0)
|
||||
@ -89,31 +86,17 @@ namespace ColorExample
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 24-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
if (AnsiConsole.Profile.Supports(ColorSystem.TrueColor))
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 24-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(new Rule("[yellow bold underline]24-bit Colors[/]").RuleStyle("grey").LeftAligned());
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
var index = 0;
|
||||
for (var i = 0.0005; i < 1; i += 0.0025)
|
||||
{
|
||||
index++;
|
||||
|
||||
var color = Utilities.HSL2RGB(i, 0.5, 0.5);
|
||||
AnsiConsole.Background = new Color(color.R, color.G, color.B);
|
||||
AnsiConsole.Write(" ");
|
||||
|
||||
if (index % 50 == 0)
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
}
|
||||
}
|
||||
AnsiConsole.Render(new ColorBox(width: 80, height: 15));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace ColorExample
|
||||
{
|
||||
public static class Utilities
|
||||
{
|
||||
// Borrowed from https://geekymonkey.com/Programming/CSharp/RGB2HSL_HSL2RGB.htm
|
||||
public static Color HSL2RGB(double h, double sl, double l)
|
||||
{
|
||||
double v;
|
||||
double r, g, b;
|
||||
|
||||
r = l; // default to gray
|
||||
g = l;
|
||||
b = l;
|
||||
v = (l <= 0.5) ? (l * (1.0 + sl)) : (l + sl - l * sl);
|
||||
|
||||
if (v > 0)
|
||||
{
|
||||
double m;
|
||||
double sv;
|
||||
int sextant;
|
||||
double fract, vsf, mid1, mid2;
|
||||
|
||||
m = l + l - v;
|
||||
sv = (v - m) / v;
|
||||
h *= 6.0;
|
||||
|
||||
sextant = (int)h;
|
||||
fract = h - sextant;
|
||||
vsf = v * sv * fract;
|
||||
mid1 = m + vsf;
|
||||
mid2 = v - vsf;
|
||||
|
||||
switch (sextant)
|
||||
{
|
||||
case 0:
|
||||
r = v;
|
||||
g = mid1;
|
||||
b = m;
|
||||
break;
|
||||
case 1:
|
||||
r = mid2;
|
||||
g = v;
|
||||
b = m;
|
||||
break;
|
||||
case 2:
|
||||
r = m;
|
||||
g = v;
|
||||
b = mid1;
|
||||
break;
|
||||
case 3:
|
||||
r = m;
|
||||
g = mid2;
|
||||
b = v;
|
||||
break;
|
||||
case 4:
|
||||
r = mid1;
|
||||
g = m;
|
||||
b = v;
|
||||
break;
|
||||
case 5:
|
||||
r = v;
|
||||
g = m;
|
||||
b = mid2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new Color(
|
||||
Convert.ToByte(r * 255.0f),
|
||||
Convert.ToByte(g * 255.0f),
|
||||
Convert.ToByte(b * 255.0f));
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace ColumnsExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColumnsExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public sealed class User
|
||||
{
|
||||
@ -22,9 +22,9 @@ namespace ColumnsExample
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Brandon",
|
||||
LastName = "Cole",
|
||||
City = "Washington",
|
||||
FirstName = "Phil",
|
||||
LastName = "Scott",
|
||||
City = "Dayton",
|
||||
Country = "United States",
|
||||
},
|
||||
new User
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Cursor
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace EmojiExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Security.Authentication;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Exceptions
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace EmojiExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace GridExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace InfoExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace LinkExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace PanelExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ProgressExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class DescriptionGenerator
|
||||
{
|
||||
|
@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace ProgressExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -13,7 +13,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Cursor
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace EmojiExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,108 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Showcase
|
||||
{
|
||||
public static partial class Program
|
||||
{
|
||||
public sealed class ColorBox : Renderable
|
||||
{
|
||||
private readonly int _height;
|
||||
|
||||
public ColorBox(int height)
|
||||
{
|
||||
_height = height;
|
||||
}
|
||||
|
||||
protected override Measurement Measure(RenderContext context, int maxWidth)
|
||||
{
|
||||
return new Measurement(1, maxWidth);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Segment> Render(RenderContext context, int maxWidth)
|
||||
{
|
||||
for (var y = 0; y < _height; y++)
|
||||
{
|
||||
for (var x = 0; x < maxWidth; x++)
|
||||
{
|
||||
var h = x / (float)maxWidth;
|
||||
var l = 0.1f + ((y / (float)_height) * 0.7f);
|
||||
var (r1, g1, b1) = ColorFromHSL(h, l, 1.0f);
|
||||
var (r2, g2, b2) = ColorFromHSL(h, l + (0.7f / 10), 1.0f);
|
||||
|
||||
var background = new Color((byte)(r1 * 255), (byte)(g1 * 255), (byte)(b1 * 255));
|
||||
var foreground = new Color((byte)(r2 * 255), (byte)(g2 * 255), (byte)(b2 * 255));
|
||||
|
||||
yield return new Segment("▄", new Style(foreground, background));
|
||||
}
|
||||
|
||||
yield return Segment.LineBreak;
|
||||
}
|
||||
}
|
||||
|
||||
private static (float, float, float) ColorFromHSL(double h, double l, double s)
|
||||
{
|
||||
double r = 0, g = 0, b = 0;
|
||||
if (l != 0)
|
||||
{
|
||||
if (s == 0)
|
||||
{
|
||||
r = g = b = l;
|
||||
}
|
||||
else
|
||||
{
|
||||
double temp2;
|
||||
if (l < 0.5)
|
||||
{
|
||||
temp2 = l * (1.0 + s);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp2 = l + s - (l * s);
|
||||
}
|
||||
|
||||
var temp1 = 2.0 * l - temp2;
|
||||
|
||||
r = GetColorComponent(temp1, temp2, h + 1.0 / 3.0);
|
||||
g = GetColorComponent(temp1, temp2, h);
|
||||
b = GetColorComponent(temp1, temp2, h - 1.0 / 3.0);
|
||||
}
|
||||
}
|
||||
|
||||
return ((float)r, (float)g, (float)b);
|
||||
|
||||
}
|
||||
|
||||
private static double GetColorComponent(double temp1, double temp2, double temp3)
|
||||
{
|
||||
if (temp3 < 0.0)
|
||||
{
|
||||
temp3 += 1.0;
|
||||
}
|
||||
else if (temp3 > 1.0)
|
||||
{
|
||||
temp3 -= 1.0;
|
||||
}
|
||||
|
||||
if (temp3 < 1.0 / 6.0)
|
||||
{
|
||||
return temp1 + (temp2 - temp1) * 6.0 * temp3;
|
||||
}
|
||||
else if (temp3 < 0.5)
|
||||
{
|
||||
return temp2;
|
||||
}
|
||||
else if (temp3 < 2.0 / 3.0)
|
||||
{
|
||||
return temp1 + ((temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return temp1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Showcase
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class ExceptionGenerator
|
||||
{
|
||||
|
@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using Spectre.Console;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using System.Threading;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Showcase
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static partial class Program
|
||||
{
|
||||
@ -102,7 +98,7 @@ namespace Showcase
|
||||
"✓ [bold purple]8-bit color[/]\n" +
|
||||
"✓ [bold yellow]Truecolor (16.7 million)[/]\n" +
|
||||
"✓ [bold aqua]Automatic color conversion[/]"),
|
||||
new ColorBox(6));
|
||||
new ColorBox(height: 6));
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
@ -1,16 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<ExampleTitle>Showcase</ExampleTitle>
|
||||
<ExampleDescription>Demonstation of Spectre.Console.</ExampleDescription>
|
||||
<ExampleGroup>Misc</ExampleGroup>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console.ImageSharp\Spectre.Console.ImageSharp.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System.Threading;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace ProgressExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -13,7 +13,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace TableExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace TableExample
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
124
examples/Shared/ColorBox.cs
Normal file
124
examples/Shared/ColorBox.cs
Normal file
@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public sealed class ColorBox : Renderable
|
||||
{
|
||||
private readonly int _height;
|
||||
private int? _width;
|
||||
|
||||
public ColorBox(int height)
|
||||
{
|
||||
_height = height;
|
||||
}
|
||||
|
||||
public ColorBox(int width, int height)
|
||||
: this(height)
|
||||
{
|
||||
_width = width;
|
||||
}
|
||||
|
||||
protected override Measurement Measure(RenderContext context, int maxWidth)
|
||||
{
|
||||
return new Measurement(1, GetWidth(maxWidth));
|
||||
}
|
||||
|
||||
protected override IEnumerable<Segment> Render(RenderContext context, int maxWidth)
|
||||
{
|
||||
maxWidth = GetWidth(maxWidth);
|
||||
|
||||
for (var y = 0; y < _height; y++)
|
||||
{
|
||||
for (var x = 0; x < maxWidth; x++)
|
||||
{
|
||||
var h = x / (float)maxWidth;
|
||||
var l = 0.1f + ((y / (float)_height) * 0.7f);
|
||||
var (r1, g1, b1) = ColorFromHSL(h, l, 1.0f);
|
||||
var (r2, g2, b2) = ColorFromHSL(h, l + (0.7f / 10), 1.0f);
|
||||
|
||||
var background = new Color((byte)(r1 * 255), (byte)(g1 * 255), (byte)(b1 * 255));
|
||||
var foreground = new Color((byte)(r2 * 255), (byte)(g2 * 255), (byte)(b2 * 255));
|
||||
|
||||
yield return new Segment("▄", new Style(foreground, background));
|
||||
}
|
||||
|
||||
yield return Segment.LineBreak;
|
||||
}
|
||||
}
|
||||
|
||||
private int GetWidth(int maxWidth)
|
||||
{
|
||||
var width = maxWidth;
|
||||
if (_width != null)
|
||||
{
|
||||
width = Math.Min(_width.Value, width);
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
private static (float, float, float) ColorFromHSL(double h, double l, double s)
|
||||
{
|
||||
double r = 0, g = 0, b = 0;
|
||||
if (l != 0)
|
||||
{
|
||||
if (s == 0)
|
||||
{
|
||||
r = g = b = l;
|
||||
}
|
||||
else
|
||||
{
|
||||
double temp2;
|
||||
if (l < 0.5)
|
||||
{
|
||||
temp2 = l * (1.0 + s);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp2 = l + s - (l * s);
|
||||
}
|
||||
|
||||
var temp1 = 2.0 * l - temp2;
|
||||
|
||||
r = GetColorComponent(temp1, temp2, h + 1.0 / 3.0);
|
||||
g = GetColorComponent(temp1, temp2, h);
|
||||
b = GetColorComponent(temp1, temp2, h - 1.0 / 3.0);
|
||||
}
|
||||
}
|
||||
|
||||
return ((float)r, (float)g, (float)b);
|
||||
|
||||
}
|
||||
|
||||
private static double GetColorComponent(double temp1, double temp2, double temp3)
|
||||
{
|
||||
if (temp3 < 0.0)
|
||||
{
|
||||
temp3 += 1.0;
|
||||
}
|
||||
else if (temp3 > 1.0)
|
||||
{
|
||||
temp3 -= 1.0;
|
||||
}
|
||||
|
||||
if (temp3 < 1.0 / 6.0)
|
||||
{
|
||||
return temp1 + (temp2 - temp1) * 6.0 * temp3;
|
||||
}
|
||||
else if (temp3 < 0.5)
|
||||
{
|
||||
return temp2;
|
||||
}
|
||||
else if (temp3 < 2.0 / 3.0)
|
||||
{
|
||||
return temp1 + ((temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return temp1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
examples/Shared/Extensions/ColorExtensions.cs
Normal file
15
examples/Shared/Extensions/ColorExtensions.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace Spectre.Console.Examples
|
||||
{
|
||||
public static class ColorExtensions
|
||||
{
|
||||
public static Color GetInvertedColor(this Color color)
|
||||
{
|
||||
return GetLuminance(color) < 140 ? Color.White : Color.Black;
|
||||
}
|
||||
|
||||
private static float GetLuminance(this Color color)
|
||||
{
|
||||
return (float)((0.2126 * color.R) + (0.7152 * color.G) + (0.0722 * color.B));
|
||||
}
|
||||
}
|
||||
}
|
12
examples/Shared/Shared.csproj
Normal file
12
examples/Shared/Shared.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<ExampleVisible>false</ExampleVisible>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,8 +1,6 @@
|
||||
using Shouldly;
|
||||
using Spectre.Console.Cli;
|
||||
using Spectre.Console.Testing;
|
||||
using Spectre.Console.Tests.Data;
|
||||
using VerifyXunit;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit.Cli
|
||||
|
@ -82,6 +82,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logging", "..\examples\Cli\
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Showcase", "..\examples\Console\Showcase\Showcase.csproj", "{4C30C028-E97D-4B4C-AD17-C90F338A4DFF}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{A0C772BA-C5F4-451D-AA7A-4045F2FA0201}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "..\examples\Shared\Shared.csproj", "{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -440,6 +444,18 @@ Global
|
||||
{4C30C028-E97D-4B4C-AD17-C90F338A4DFF}.Release|x64.Build.0 = Release|Any CPU
|
||||
{4C30C028-E97D-4B4C-AD17-C90F338A4DFF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{4C30C028-E97D-4B4C-AD17-C90F338A4DFF}.Release|x86.Build.0 = Release|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Release|x64.Build.0 = Release|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -473,6 +489,8 @@ Global
|
||||
{CA7AF967-3FA5-4CB1-9564-740CF4527895} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{33C7075A-DF97-44FC-8AB3-0CCFBA03341A} = {42792D7F-0BB6-4EE1-A314-8889305A4C48}
|
||||
{4C30C028-E97D-4B4C-AD17-C90F338A4DFF} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{A0C772BA-C5F4-451D-AA7A-4045F2FA0201} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{8428A7DD-29FC-4417-9CA0-B90D34B26AB2} = {A0C772BA-C5F4-451D-AA7A-4045F2FA0201}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5729B071-67A0-48FB-8B1B-275E6822086C}
|
||||
|
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user