diff --git a/examples/Cli/Delegates/BarSettings.cs b/examples/Cli/Delegates/BarSettings.cs index 75fa93cf..61dc9f79 100644 --- a/examples/Cli/Delegates/BarSettings.cs +++ b/examples/Cli/Delegates/BarSettings.cs @@ -1,7 +1,7 @@ using System.ComponentModel; using Spectre.Console.Cli; -namespace Delegates +namespace Spectre.Console.Examples { public static partial class Program { diff --git a/examples/Cli/Delegates/Delegates.csproj b/examples/Cli/Delegates/Delegates.csproj index 4c6756c7..4a163f36 100644 --- a/examples/Cli/Delegates/Delegates.csproj +++ b/examples/Cli/Delegates/Delegates.csproj @@ -1,4 +1,4 @@ - + Exe @@ -11,7 +11,7 @@ - + diff --git a/examples/Cli/Delegates/Program.cs b/examples/Cli/Delegates/Program.cs index 65923729..2523ddbe 100644 --- a/examples/Cli/Delegates/Program.cs +++ b/examples/Cli/Delegates/Program.cs @@ -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; diff --git a/examples/Cli/Dynamic/Dynamic.csproj b/examples/Cli/Dynamic/Dynamic.csproj index 2066c580..93e4730a 100644 --- a/examples/Cli/Dynamic/Dynamic.csproj +++ b/examples/Cli/Dynamic/Dynamic.csproj @@ -1,4 +1,4 @@ - + Exe @@ -11,7 +11,7 @@ - + diff --git a/examples/Cli/Dynamic/MyCommand.cs b/examples/Cli/Dynamic/MyCommand.cs index b16caa89..220a6b1a 100644 --- a/examples/Cli/Dynamic/MyCommand.cs +++ b/examples/Cli/Dynamic/MyCommand.cs @@ -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; } } diff --git a/examples/Cli/Dynamic/Program.cs b/examples/Cli/Dynamic/Program.cs index 519fab7a..b90e53c6 100644 --- a/examples/Cli/Dynamic/Program.cs +++ b/examples/Cli/Dynamic/Program.cs @@ -1,7 +1,7 @@ using System.Linq; using Spectre.Console.Cli; -namespace Dynamic +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Cli/Injection/Commands/DefaultCommand.cs b/examples/Cli/Injection/Commands/DefaultCommand.cs index 1ae059ff..fe2e282c 100644 --- a/examples/Cli/Injection/Commands/DefaultCommand.cs +++ b/examples/Cli/Injection/Commands/DefaultCommand.cs @@ -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 { diff --git a/examples/Cli/Injection/IGreeter.cs b/examples/Cli/Injection/IGreeter.cs index a2c285b3..be7d8889 100644 --- a/examples/Cli/Injection/IGreeter.cs +++ b/examples/Cli/Injection/IGreeter.cs @@ -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}!"); } } } diff --git a/examples/Cli/Injection/Infrastructure/TypeRegistrar.cs b/examples/Cli/Injection/Infrastructure/TypeRegistrar.cs index c0e33424..ce9b3642 100644 --- a/examples/Cli/Injection/Infrastructure/TypeRegistrar.cs +++ b/examples/Cli/Injection/Infrastructure/TypeRegistrar.cs @@ -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 { diff --git a/examples/Cli/Injection/Infrastructure/TypeResolver.cs b/examples/Cli/Injection/Infrastructure/TypeResolver.cs index dde7dc17..8ff91be1 100644 --- a/examples/Cli/Injection/Infrastructure/TypeResolver.cs +++ b/examples/Cli/Injection/Infrastructure/TypeResolver.cs @@ -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 { diff --git a/examples/Cli/Injection/Injection.csproj b/examples/Cli/Injection/Injection.csproj index 4c14b62e..99b99232 100644 --- a/examples/Cli/Injection/Injection.csproj +++ b/examples/Cli/Injection/Injection.csproj @@ -15,7 +15,7 @@ - + diff --git a/examples/Cli/Injection/Program.cs b/examples/Cli/Injection/Program.cs index 1206df9d..8ebaa0c9 100644 --- a/examples/Cli/Injection/Program.cs +++ b/examples/Cli/Injection/Program.cs @@ -1,8 +1,7 @@ -using Injection.Commands; using Microsoft.Extensions.DependencyInjection; using Spectre.Console.Cli; -namespace Injection +namespace Spectre.Console.Examples { public class Program { diff --git a/examples/Cli/Logging/Commands/HelloCommand.cs b/examples/Cli/Logging/Commands/HelloCommand.cs index 710f136d..2bbff0c6 100644 --- a/examples/Cli/Logging/Commands/HelloCommand.cs +++ b/examples/Cli/Logging/Commands/HelloCommand.cs @@ -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 { diff --git a/examples/Cli/Logging/Commands/LogCommandSettings.cs b/examples/Cli/Logging/Commands/LogCommandSettings.cs index 4160e9db..da47b564 100644 --- a/examples/Cli/Logging/Commands/LogCommandSettings.cs +++ b/examples/Cli/Logging/Commands/LogCommandSettings.cs @@ -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 { diff --git a/examples/Cli/Logging/Infrastructure/LogInterceptor.cs b/examples/Cli/Logging/Infrastructure/LogInterceptor.cs index 423a640e..31adaff7 100644 --- a/examples/Cli/Logging/Infrastructure/LogInterceptor.cs +++ b/examples/Cli/Logging/Infrastructure/LogInterceptor.cs @@ -1,8 +1,7 @@ -using Logging.Commands; using Serilog.Core; using Spectre.Console.Cli; -namespace Logging +namespace Spectre.Console.Examples { public class LogInterceptor : ICommandInterceptor { diff --git a/examples/Cli/Logging/Infrastructure/LoggingEnricher.cs b/examples/Cli/Logging/Infrastructure/LoggingEnricher.cs index 86007a79..e9e41e28 100644 --- a/examples/Cli/Logging/Infrastructure/LoggingEnricher.cs +++ b/examples/Cli/Logging/Infrastructure/LoggingEnricher.cs @@ -1,7 +1,7 @@ -using Serilog.Core; +using Serilog.Core; using Serilog.Events; -namespace Logging +namespace Spectre.Console.Examples { internal class LoggingEnricher : ILogEventEnricher { diff --git a/examples/Cli/Logging/Infrastructure/TypeRegistrar.cs b/examples/Cli/Logging/Infrastructure/TypeRegistrar.cs index 7975df41..bd7692f3 100644 --- a/examples/Cli/Logging/Infrastructure/TypeRegistrar.cs +++ b/examples/Cli/Logging/Infrastructure/TypeRegistrar.cs @@ -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 { diff --git a/examples/Cli/Logging/Infrastructure/TypeResolver.cs b/examples/Cli/Logging/Infrastructure/TypeResolver.cs index 6e95cabb..e449c85e 100644 --- a/examples/Cli/Logging/Infrastructure/TypeResolver.cs +++ b/examples/Cli/Logging/Infrastructure/TypeResolver.cs @@ -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 { diff --git a/examples/Cli/Logging/Logging.csproj b/examples/Cli/Logging/Logging.csproj index 6cc49607..8fe73db0 100644 --- a/examples/Cli/Logging/Logging.csproj +++ b/examples/Cli/Logging/Logging.csproj @@ -20,7 +20,7 @@ - + diff --git a/examples/Cli/Logging/Program.cs b/examples/Cli/Logging/Program.cs index 5ed226ad..16f3517a 100644 --- a/examples/Cli/Logging/Program.cs +++ b/examples/Cli/Logging/Program.cs @@ -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 { diff --git a/examples/Console/Borders/Borders.csproj b/examples/Console/Borders/Borders.csproj index f51cc16f..3d8b7b92 100644 --- a/examples/Console/Borders/Borders.csproj +++ b/examples/Console/Borders/Borders.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Borders/Program.cs b/examples/Console/Borders/Program.cs index 28541072..a0dc06a0 100644 --- a/examples/Console/Borders/Program.cs +++ b/examples/Console/Borders/Program.cs @@ -1,7 +1,6 @@ -using Spectre.Console; using Spectre.Console.Rendering; -namespace BordersExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Calendars/Calendars.csproj b/examples/Console/Calendars/Calendars.csproj index 119a4795..6e58f4ff 100644 --- a/examples/Console/Calendars/Calendars.csproj +++ b/examples/Console/Calendars/Calendars.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Calendars/Program.cs b/examples/Console/Calendars/Program.cs index 1ac1b493..fbe2311b 100644 --- a/examples/Console/Calendars/Program.cs +++ b/examples/Console/Calendars/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace Calendars +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Canvas/Canvas.csproj b/examples/Console/Canvas/Canvas.csproj index 182d9e5a..96055f0f 100644 --- a/examples/Console/Canvas/Canvas.csproj +++ b/examples/Console/Canvas/Canvas.csproj @@ -9,8 +9,8 @@ + - diff --git a/examples/Console/Canvas/Mandelbrot.cs b/examples/Console/Canvas/Mandelbrot.cs index 7f3a3da7..005b2d1c 100644 --- a/examples/Console/Canvas/Mandelbrot.cs +++ b/examples/Console/Canvas/Mandelbrot.cs @@ -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 { diff --git a/examples/Console/Canvas/Program.cs b/examples/Console/Canvas/Program.cs index 29827eb6..0e2ce7e4 100644 --- a/examples/Console/Canvas/Program.cs +++ b/examples/Console/Canvas/Program.cs @@ -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 { diff --git a/examples/Console/Charts/Charts.csproj b/examples/Console/Charts/Charts.csproj index 3763e82b..f9190efa 100644 --- a/examples/Console/Charts/Charts.csproj +++ b/examples/Console/Charts/Charts.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Charts/Program.cs b/examples/Console/Charts/Program.cs index 229047f0..f0c7664f 100644 --- a/examples/Console/Charts/Program.cs +++ b/examples/Console/Charts/Program.cs @@ -1,7 +1,6 @@ -using Spectre.Console; using Spectre.Console.Rendering; -namespace Charts +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Colors/Colors.csproj b/examples/Console/Colors/Colors.csproj index 32185ad4..f4967f03 100644 --- a/examples/Console/Colors/Colors.csproj +++ b/examples/Console/Colors/Colors.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Colors/Program.cs b/examples/Console/Colors/Program.cs index 3075c8e5..5e7708d3 100644 --- a/examples/Console/Colors/Program.cs +++ b/examples/Console/Colors/Program.cs @@ -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)); } } } diff --git a/examples/Console/Colors/Utilities.cs b/examples/Console/Colors/Utilities.cs deleted file mode 100644 index 3f32bcdf..00000000 --- a/examples/Console/Colors/Utilities.cs +++ /dev/null @@ -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)); - } - } -} diff --git a/examples/Console/Columns/Columns.csproj b/examples/Console/Columns/Columns.csproj index 474b855f..543f1efe 100644 --- a/examples/Console/Columns/Columns.csproj +++ b/examples/Console/Columns/Columns.csproj @@ -13,7 +13,7 @@ - + diff --git a/examples/Console/Columns/Program.cs b/examples/Console/Columns/Program.cs index c7e90b54..9e20f15e 100644 --- a/examples/Console/Columns/Program.cs +++ b/examples/Console/Columns/Program.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; -using Spectre.Console; -namespace ColumnsExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Columns/User.cs b/examples/Console/Columns/User.cs index 4125dcc2..88e5fc7c 100644 --- a/examples/Console/Columns/User.cs +++ b/examples/Console/Columns/User.cs @@ -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 diff --git a/examples/Console/Cursor/Cursor.csproj b/examples/Console/Cursor/Cursor.csproj index 9daddacc..622ace09 100644 --- a/examples/Console/Cursor/Cursor.csproj +++ b/examples/Console/Cursor/Cursor.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Cursor/Program.cs b/examples/Console/Cursor/Program.cs index e2645c2c..796b8579 100644 --- a/examples/Console/Cursor/Program.cs +++ b/examples/Console/Cursor/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace Cursor +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Emojis/Emojis.csproj b/examples/Console/Emojis/Emojis.csproj index eceb0bda..ebb420b7 100644 --- a/examples/Console/Emojis/Emojis.csproj +++ b/examples/Console/Emojis/Emojis.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Emojis/Program.cs b/examples/Console/Emojis/Program.cs index c67932fa..b91e296d 100644 --- a/examples/Console/Emojis/Program.cs +++ b/examples/Console/Emojis/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace EmojiExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Exceptions/Exceptions.csproj b/examples/Console/Exceptions/Exceptions.csproj index 128d8c02..9797995c 100644 --- a/examples/Console/Exceptions/Exceptions.csproj +++ b/examples/Console/Exceptions/Exceptions.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Exceptions/Program.cs b/examples/Console/Exceptions/Program.cs index 559dac3d..bb9a3651 100644 --- a/examples/Console/Exceptions/Program.cs +++ b/examples/Console/Exceptions/Program.cs @@ -1,8 +1,7 @@ using System; using System.Security.Authentication; -using Spectre.Console; -namespace Exceptions +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Figlet/Figlet.csproj b/examples/Console/Figlet/Figlet.csproj index fbac2d64..88e7331a 100644 --- a/examples/Console/Figlet/Figlet.csproj +++ b/examples/Console/Figlet/Figlet.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Figlet/Program.cs b/examples/Console/Figlet/Program.cs index 0310a7b1..60f37603 100644 --- a/examples/Console/Figlet/Program.cs +++ b/examples/Console/Figlet/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace EmojiExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Grids/Grids.csproj b/examples/Console/Grids/Grids.csproj index 95c90040..d6ade50c 100644 --- a/examples/Console/Grids/Grids.csproj +++ b/examples/Console/Grids/Grids.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Grids/Program.cs b/examples/Console/Grids/Program.cs index ae594887..63204298 100644 --- a/examples/Console/Grids/Program.cs +++ b/examples/Console/Grids/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace GridExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Info/Info.csproj b/examples/Console/Info/Info.csproj index f4ec75f7..05d3666c 100644 --- a/examples/Console/Info/Info.csproj +++ b/examples/Console/Info/Info.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Info/Program.cs b/examples/Console/Info/Program.cs index 3cb5f824..2d757df0 100644 --- a/examples/Console/Info/Program.cs +++ b/examples/Console/Info/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace InfoExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Links/Links.csproj b/examples/Console/Links/Links.csproj index 5054afac..ba606338 100644 --- a/examples/Console/Links/Links.csproj +++ b/examples/Console/Links/Links.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Links/Program.cs b/examples/Console/Links/Program.cs index f61972ec..1977008e 100644 --- a/examples/Console/Links/Program.cs +++ b/examples/Console/Links/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace LinkExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Panels/Panels.csproj b/examples/Console/Panels/Panels.csproj index 03add392..10a96807 100644 --- a/examples/Console/Panels/Panels.csproj +++ b/examples/Console/Panels/Panels.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Panels/Program.cs b/examples/Console/Panels/Program.cs index d43c1103..2c61b0ba 100644 --- a/examples/Console/Panels/Program.cs +++ b/examples/Console/Panels/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace PanelExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Progress/DescriptionGenerator.cs b/examples/Console/Progress/DescriptionGenerator.cs index a4f78611..3f4f0a2b 100644 --- a/examples/Console/Progress/DescriptionGenerator.cs +++ b/examples/Console/Progress/DescriptionGenerator.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace ProgressExample +namespace Spectre.Console.Examples { public static class DescriptionGenerator { diff --git a/examples/Console/Progress/Program.cs b/examples/Console/Progress/Program.cs index 82ae6b0d..b30f96d3 100644 --- a/examples/Console/Progress/Program.cs +++ b/examples/Console/Progress/Program.cs @@ -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 { diff --git a/examples/Console/Progress/Progress.csproj b/examples/Console/Progress/Progress.csproj index 859b3f23..6a226b0f 100644 --- a/examples/Console/Progress/Progress.csproj +++ b/examples/Console/Progress/Progress.csproj @@ -13,7 +13,7 @@ - + diff --git a/examples/Console/Prompt/Program.cs b/examples/Console/Prompt/Program.cs index 0c716c2b..d9a0ac97 100644 --- a/examples/Console/Prompt/Program.cs +++ b/examples/Console/Prompt/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace Cursor +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Prompt/Prompt.csproj b/examples/Console/Prompt/Prompt.csproj index c0d2d427..3abb410e 100644 --- a/examples/Console/Prompt/Prompt.csproj +++ b/examples/Console/Prompt/Prompt.csproj @@ -10,7 +10,7 @@ - + diff --git a/examples/Console/Rules/Program.cs b/examples/Console/Rules/Program.cs index 8a03924c..7b08fff7 100644 --- a/examples/Console/Rules/Program.cs +++ b/examples/Console/Rules/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace EmojiExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Rules/Rules.csproj b/examples/Console/Rules/Rules.csproj index 7d590fc4..8447b1e3 100644 --- a/examples/Console/Rules/Rules.csproj +++ b/examples/Console/Rules/Rules.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Showcase/ColorBox.cs b/examples/Console/Showcase/ColorBox.cs deleted file mode 100644 index 4060c32c..00000000 --- a/examples/Console/Showcase/ColorBox.cs +++ /dev/null @@ -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 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; - } - } - } - } -} diff --git a/examples/Console/Showcase/ExceptionGenerator.cs b/examples/Console/Showcase/ExceptionGenerator.cs index baa66251..1f9355ee 100644 --- a/examples/Console/Showcase/ExceptionGenerator.cs +++ b/examples/Console/Showcase/ExceptionGenerator.cs @@ -1,7 +1,6 @@ using System; -using Spectre.Console; -namespace Showcase +namespace Spectre.Console.Examples { public static class ExceptionGenerator { diff --git a/examples/Console/Showcase/Program.cs b/examples/Console/Showcase/Program.cs index f91a3760..9cfb2c38 100644 --- a/examples/Console/Showcase/Program.cs +++ b/examples/Console/Showcase/Program.cs @@ -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; } diff --git a/examples/Console/Showcase/Showcase.csproj b/examples/Console/Showcase/Showcase.csproj index 99dea6de..7a6518f5 100644 --- a/examples/Console/Showcase/Showcase.csproj +++ b/examples/Console/Showcase/Showcase.csproj @@ -1,16 +1,15 @@ - + Exe - netcoreapp3.1 + net5.0 Showcase Demonstation of Spectre.Console. Misc - - + diff --git a/examples/Console/Status/Program.cs b/examples/Console/Status/Program.cs index 36fde30a..f0558ae4 100644 --- a/examples/Console/Status/Program.cs +++ b/examples/Console/Status/Program.cs @@ -1,7 +1,6 @@ using System.Threading; -using Spectre.Console; -namespace ProgressExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Status/Status.csproj b/examples/Console/Status/Status.csproj index eb20f188..d3646168 100644 --- a/examples/Console/Status/Status.csproj +++ b/examples/Console/Status/Status.csproj @@ -13,7 +13,7 @@ - + diff --git a/examples/Console/Tables/Program.cs b/examples/Console/Tables/Program.cs index ce7b6cf9..805cc2a0 100644 --- a/examples/Console/Tables/Program.cs +++ b/examples/Console/Tables/Program.cs @@ -1,7 +1,4 @@ -using System.Diagnostics; -using Spectre.Console; - -namespace TableExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Tables/Tables.csproj b/examples/Console/Tables/Tables.csproj index 451f79a1..447d3748 100644 --- a/examples/Console/Tables/Tables.csproj +++ b/examples/Console/Tables/Tables.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Console/Trees/Program.cs b/examples/Console/Trees/Program.cs index 33747cdb..df9d5871 100644 --- a/examples/Console/Trees/Program.cs +++ b/examples/Console/Trees/Program.cs @@ -1,6 +1,4 @@ -using Spectre.Console; - -namespace TableExample +namespace Spectre.Console.Examples { public static class Program { diff --git a/examples/Console/Trees/Trees.csproj b/examples/Console/Trees/Trees.csproj index 92913344..e0c3b3ac 100644 --- a/examples/Console/Trees/Trees.csproj +++ b/examples/Console/Trees/Trees.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/Shared/ColorBox.cs b/examples/Shared/ColorBox.cs new file mode 100644 index 00000000..e855f468 --- /dev/null +++ b/examples/Shared/ColorBox.cs @@ -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 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; + } + } + } +} diff --git a/examples/Shared/Extensions/ColorExtensions.cs b/examples/Shared/Extensions/ColorExtensions.cs new file mode 100644 index 00000000..0322c5ba --- /dev/null +++ b/examples/Shared/Extensions/ColorExtensions.cs @@ -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)); + } + } +} diff --git a/examples/Shared/Shared.csproj b/examples/Shared/Shared.csproj new file mode 100644 index 00000000..bdcfea00 --- /dev/null +++ b/examples/Shared/Shared.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + false + + + + + + + diff --git a/src/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Constructor.cs b/src/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Constructor.cs index 6a689baf..c86b494f 100644 --- a/src/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Constructor.cs +++ b/src/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Constructor.cs @@ -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 diff --git a/src/Spectre.Console.sln b/src/Spectre.Console.sln index 2962472c..dea20968 100644 --- a/src/Spectre.Console.sln +++ b/src/Spectre.Console.sln @@ -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} diff --git a/src/Spectre.Console/Emoji.cs b/src/Spectre.Console/Emoji.cs index 3a42c528..89afcc64 100644 --- a/src/Spectre.Console/Emoji.cs +++ b/src/Spectre.Console/Emoji.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Design; using System.Text; -using System.Text.RegularExpressions; namespace Spectre.Console {