mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add rule widget
Adds a new rule widget. Also fixes some bugs I encountered while testing some unrelated things in an extremely small console.
This commit is contained in:

committed by
Patrik Svensson

parent
1410cba6c5
commit
5a1b8a1710
@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
@ -7,6 +8,8 @@ namespace BordersExample
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Debugger.Launch();
|
||||
|
||||
// Render panel borders
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[white bold underline]PANEL BORDERS[/]");
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace ColorExample
|
||||
@ -24,7 +25,7 @@ namespace ColorExample
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[bold underline]3-bit Colors[/]");
|
||||
AnsiConsole.Render(new Rule("[yellow bold underline]3-bit Colors[/]").SetStyle("grey").LeftAligned());
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
@ -47,7 +48,7 @@ namespace ColorExample
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[bold underline]4-bit Colors[/]");
|
||||
AnsiConsole.Render(new Rule("[yellow bold underline]4-bit Colors[/]").SetStyle("grey").LeftAligned());
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
for (var i = 0; i < 16; i++)
|
||||
@ -70,7 +71,7 @@ namespace ColorExample
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[bold underline]8-bit Colors[/]");
|
||||
AnsiConsole.Render(new Rule("[yellow bold underline]8-bit Colors[/]").SetStyle("grey").LeftAligned());
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
for (var i = 0; i < 16; i++)
|
||||
@ -97,7 +98,7 @@ namespace ColorExample
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[bold underline]24-bit Colors[/]");
|
||||
AnsiConsole.Render(new Rule("[yellow bold underline]24-bit Colors[/]").SetStyle("grey").LeftAligned());
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
var index = 0;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
@ -15,17 +15,17 @@ namespace Exceptions
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(new Panel("[u]Default[/]").Expand());
|
||||
AnsiConsole.Render(new Rule("Default").LeftAligned());
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.WriteException(ex);
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(new Panel("[u]Compact[/]").Expand());
|
||||
AnsiConsole.Render(new Rule("Compact").LeftAligned());
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.WriteException(ex, ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks);
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(new Panel("[u]Custom colors[/]").Expand());
|
||||
AnsiConsole.Render(new Rule("Compact + Custom colors").LeftAligned());
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.WriteException(ex, new ExceptionSettings
|
||||
{
|
||||
|
28
examples/Rules/Program.cs
Normal file
28
examples/Rules/Program.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace EmojiExample
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// No title
|
||||
Render(new Rule().SetStyle("yellow"));
|
||||
|
||||
// Left aligned title
|
||||
Render(new Rule("[white]Left aligned[/]").LeftAligned().SetStyle("red"));
|
||||
|
||||
// Centered title
|
||||
Render(new Rule("[silver]Centered[/]").Centered().SetStyle("green"));
|
||||
|
||||
// Right aligned title
|
||||
Render(new Rule("[grey]Right aligned[/]").RightAligned().SetStyle("blue"));
|
||||
}
|
||||
|
||||
private static void Render(Rule rule)
|
||||
{
|
||||
AnsiConsole.Render(new Panel(rule).Expand().SetBorderStyle(Style.Parse("grey")));
|
||||
AnsiConsole.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
15
examples/Rules/Rules.csproj
Normal file
15
examples/Rules/Rules.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Title>Rules</Title>
|
||||
<Description>Demonstrates how to render horizontal rules (lines).</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user