mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-10-25 15:19:23 +00:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
697273917e | ||
|
|
2943535973 | ||
|
|
cd0d182f12 | ||
|
|
b197f278ed | ||
|
|
3847a8949f | ||
|
|
eeb3f967b6 | ||
|
|
090b30f731 | ||
|
|
df291ef84e | ||
|
|
7d6104ace4 | ||
|
|
314456ca17 | ||
|
|
b7f654cd7f | ||
|
|
fea8a36e8a | ||
|
|
0632b38477 | ||
|
|
a7b7d4e556 | ||
|
|
11d331e31d | ||
|
|
ce670a7ca9 | ||
|
|
101e244059 | ||
|
|
504746c5dc | ||
|
|
1601ef24b3 | ||
|
|
b46d0fa4f6 | ||
|
|
4f06687104 | ||
|
|
003e15686f | ||
|
|
3e9796849b | ||
|
|
3cc19520b0 | ||
|
|
87bde3e5a2 | ||
|
|
e6e9a4d950 | ||
|
|
29ce14e1e8 | ||
|
|
ceb3572d6a | ||
|
|
13c56eca01 | ||
|
|
a477884d36 |
3
.github/workflows/ci.yaml
vendored
3
.github/workflows/ci.yaml
vendored
@@ -64,11 +64,12 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
dotnet tool restore
|
||||
dotnet example diagnostic
|
||||
dotnet example info
|
||||
dotnet example table
|
||||
dotnet example grid
|
||||
dotnet example panel
|
||||
dotnet example colors
|
||||
dotnet example emojis
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@
|
||||
[Pp]ackages/
|
||||
/.artifacts/
|
||||
/[Tt]ools/
|
||||
.DS_Store
|
||||
|
||||
# Cakeup
|
||||
cakeup-x86_64-latest.exe
|
||||
|
||||
@@ -22,11 +22,23 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="src\Data\emojis.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="src\Data\emojis.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Statiq.Web" Version="1.0.0-beta.5" />
|
||||
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="input\assets\images\emojis\" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="Versioning" BeforeTargets="MinVer">
|
||||
<PropertyGroup Label="Build">
|
||||
<MinVerDefaultPreReleasePhase>preview</MinVerDefaultPreReleasePhase>
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Docs
|
||||
.ConfigureDeployment(deployBranch: "docs")
|
||||
.AddShortcode("Children", typeof(ChildrenShortcode))
|
||||
.AddShortcode("ColorTable", typeof(ColorTableShortcode))
|
||||
.AddShortcode("EmojiTable", typeof(EmojiTableShortcode))
|
||||
.AddPipelines()
|
||||
.RunAsync();
|
||||
|
||||
|
||||
@@ -128,14 +128,28 @@
|
||||
{
|
||||
IDocument root = OutputPages["index.html"].First();
|
||||
<div class="sidebar-nav-item @(Document.IdEquals(root) ? "active" : null)">
|
||||
@Html.DocumentLink(root)
|
||||
@if(root.ShowLink())
|
||||
{
|
||||
@Html.DocumentLink(root)
|
||||
}
|
||||
else
|
||||
{
|
||||
@root.GetTitle()
|
||||
}
|
||||
</div>
|
||||
|
||||
@foreach (IDocument document in OutputPages.GetChildrenOf(root).OnlyVisible())
|
||||
{
|
||||
DocumentList<IDocument> documentChildren = OutputPages.GetChildrenOf(document);
|
||||
<div class="sidebar-nav-item @(Document.IdEquals(document) ? "active" : null) @(documentChildren.Any() ? "has-children" : null)">
|
||||
@Html.DocumentLink(document)
|
||||
@if(document.ShowLink())
|
||||
{
|
||||
@Html.DocumentLink(document)
|
||||
}
|
||||
else
|
||||
{
|
||||
@document.GetTitle()
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (documentChildren.OnlyVisible().Any())
|
||||
|
||||
19
docs/input/appendix/borders.md
Normal file
19
docs/input/appendix/borders.md
Normal file
@@ -0,0 +1,19 @@
|
||||
Title: Borders
|
||||
Order: 2
|
||||
---
|
||||
|
||||
There is different built-in borders you can use for tables and panels.
|
||||
|
||||
# Built-in borders
|
||||
|
||||
<img src="../assets/images/borders.png" style="max-width: 100%;">
|
||||
|
||||
# Usage
|
||||
|
||||
To create a table and set it's border to `SimpleHeavy` as seen in the
|
||||
image above:
|
||||
|
||||
```csharp
|
||||
var table = new Table();
|
||||
table.Border = Border.SimpleHeavy;
|
||||
```
|
||||
@@ -1,5 +1,5 @@
|
||||
Title: Colors
|
||||
Order: 4
|
||||
Order: 0
|
||||
---
|
||||
|
||||
The following is a list of the standard 8-bit colors supported in terminals.
|
||||
38
docs/input/appendix/emojis.md
Normal file
38
docs/input/appendix/emojis.md
Normal file
@@ -0,0 +1,38 @@
|
||||
Title: Emojis
|
||||
Order: 3
|
||||
---
|
||||
|
||||
Please note that what emojis that can be used is completely up to
|
||||
the operating system and/or terminal you're using, and no guarantees
|
||||
can be made of how it will look. Calculating the width of emojis
|
||||
is also not an exact science in many ways, so milage might vary when
|
||||
used in tables, panels or grids.
|
||||
|
||||
To ensure best compatibility, consider only using emojis introduced
|
||||
before Unicode 13.0 that belongs in the `Emoji_Presentation` category
|
||||
in the official emoji list at
|
||||
https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt
|
||||
|
||||
# Usage
|
||||
|
||||
```csharp
|
||||
// Markup
|
||||
AnsiConsole.MarkupLine("Hello :globe_showing_europe_africa:!");
|
||||
|
||||
// Constant
|
||||
var hello = "Hello " + Emoji.Known.GlobeShowingEuropeAfrica;
|
||||
```
|
||||
|
||||
# Replacing emojis in text
|
||||
|
||||
```csharp
|
||||
var phrase = "Mmmm :birthday_cake:";
|
||||
var rendered = Emoji.Replace(phrase);
|
||||
```
|
||||
|
||||
# Emojis
|
||||
|
||||
_The images in the table below might not render correctly in your
|
||||
browser for the same reasons mentioned in the `Compatibility` section._
|
||||
|
||||
<?# EmojiTable /?>
|
||||
10
docs/input/appendix/index.md
Normal file
10
docs/input/appendix/index.md
Normal file
@@ -0,0 +1,10 @@
|
||||
Title: Appendix
|
||||
Order: 10
|
||||
---
|
||||
|
||||
# Sections
|
||||
|
||||
* [Styles](xref:styles)
|
||||
* [Colors](xref:colors)
|
||||
* [Borders](xref:borders)
|
||||
* [Emojis](xref:emojis)
|
||||
44
docs/input/appendix/styles.md
Normal file
44
docs/input/appendix/styles.md
Normal file
@@ -0,0 +1,44 @@
|
||||
Title: Styles
|
||||
Order: 1
|
||||
---
|
||||
|
||||
Note that what styles that can be used is defined by the system or your terminal software, and may not appear as they should.
|
||||
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td><code>bold</code></td>
|
||||
<td>Bold text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>dim</code></td>
|
||||
<td>Dim or faint text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>italic</code></td>
|
||||
<td>Italic text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>underline</code></td>
|
||||
<td>Underlined text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>invert</code></td>
|
||||
<td>Swaps the foreground and background colors</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>conceal</code></td>
|
||||
<td>Hides the text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>slowblink</code></td>
|
||||
<td>Makes text blink slowly</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>rapidblink</code></td>
|
||||
<td>Makes text blink</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>strikethrough</code></td>
|
||||
<td>Shows text with a horizontal line through the center</td>
|
||||
</tr>
|
||||
</table>
|
||||
BIN
docs/input/assets/images/borders.png
Normal file
BIN
docs/input/assets/images/borders.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 415 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB |
BIN
docs/input/assets/images/table.png
Normal file
BIN
docs/input/assets/images/table.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
@@ -1,21 +1,18 @@
|
||||
Title: Markup
|
||||
Order: 3
|
||||
Hidden: False
|
||||
Order: 2
|
||||
---
|
||||
|
||||
In `Spectre.Console` there's a class called `Markup` that
|
||||
allows you to output rich text to the console.
|
||||
The class `Markup` allows you to output rich text to the console.
|
||||
|
||||
# Syntax
|
||||
|
||||
Console markup uses a syntax inspired by bbcode. If you write the style (see Styles)
|
||||
in square brackets, e.g. `[bold red]`, that style will apply until it is closed with a `[/]`.
|
||||
|
||||
```csharp
|
||||
AnsiConsole.Render(new Markup("[bold yellow]Hello[/] [red]World![/]"));
|
||||
```
|
||||
|
||||
Which should output something similar to the image below. Note that the
|
||||
actual appearance might vary depending on your terminal.
|
||||
|
||||

|
||||
|
||||
|
||||
The `Markup` class implements `IRenderable` which means that you
|
||||
can use this in tables, grids, and panels. Most classes that support
|
||||
rendering of `IRenderable` also have overloads for rendering rich text.
|
||||
@@ -56,49 +53,20 @@ You can set the background color in markup by prefixing the color with
|
||||
[default on blue]World[/]
|
||||
```
|
||||
|
||||
# Rendering emojis
|
||||
|
||||
To output an emoji as part of markup, you can use emoji shortcodes.
|
||||
|
||||
```csharp
|
||||
AnsiConsole.MarkupLine("Hello :globe_showing_europe_africa:!");
|
||||
```
|
||||
|
||||
For a list of emoji, see the [Emojis](xref:styles) appendix section.
|
||||
|
||||
# Colors
|
||||
|
||||
For a list of colors, see the [Colors](xref:colors) section.
|
||||
For a list of colors, see the [Colors](xref:colors) appendix section.
|
||||
|
||||
# Styles
|
||||
|
||||
Note that what styles that can be used is defined by the system or your terminal software, and may not appear as they should.
|
||||
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td><code>bold</code></td>
|
||||
<td>Bold text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>dim</code></td>
|
||||
<td>Dim or faint text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>italic</code></td>
|
||||
<td>Italic text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>underline</code></td>
|
||||
<td>Underlined text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>invert</code></td>
|
||||
<td>Swaps the foreground and background colors</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>conceal</code></td>
|
||||
<td>Hides the text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>slowblink</code></td>
|
||||
<td>Makes text blink slowly</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>rapidblink</code></td>
|
||||
<td>Makes text blink</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>strikethrough</code></td>
|
||||
<td>Shows text with a horizontal line through the center</td>
|
||||
</tr>
|
||||
</table>
|
||||
For a list of styles, see the [Styles](xref:styles) appendix section.
|
||||
120
docs/input/tables.md
Normal file
120
docs/input/tables.md
Normal file
@@ -0,0 +1,120 @@
|
||||
Title: Tables
|
||||
Order: 3
|
||||
---
|
||||
|
||||
Tables are a perfect way of displaying tabular data in a terminal.
|
||||
|
||||
`Spectre.Console` is super smart about rendering tables and will adjust
|
||||
all columns to fit whatever is inside them. Anything that implements
|
||||
`IRenderable` can be used as a column header or column cell, even another table!
|
||||
|
||||
# Usage
|
||||
|
||||
<!------------------------->
|
||||
<!--- USAGE --->
|
||||
<!------------------------->
|
||||
|
||||
To render a table, create a `Table` instance, add the number of
|
||||
columns that you need, and then add the rows. Finish by passing the
|
||||
table to a console's `Render` method.
|
||||
|
||||
```csharp
|
||||
// Create a table
|
||||
var table = new Table();
|
||||
|
||||
// Add some columns
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn(new TableColumn("Bar").Centered());
|
||||
|
||||
// Add some rows
|
||||
table.AddRow("Baz", "[green]Qux[/]");
|
||||
table.AddRow(new Markup("[blue]Corgi[/]"), new Panel("Waldo"));
|
||||
|
||||
// Render the table to the console
|
||||
AnsiConsole.Render(table);
|
||||
```
|
||||
|
||||
This will render the following output:
|
||||
|
||||

|
||||
|
||||
# Table appearance
|
||||
|
||||
<!------------------------->
|
||||
<!--- TABLE APPEARANCE --->
|
||||
<!------------------------->
|
||||
|
||||
## Borders
|
||||
|
||||
For a list of borders, see the [Borders](xref:borders) appendix section.
|
||||
|
||||
```csharp
|
||||
// Sets the border
|
||||
table.SetBorder(Border.None);
|
||||
table.SetBorder(Border.Ascii);
|
||||
table.SetBorder(Border.Square);
|
||||
table.SetBorder(Border.Rounded);
|
||||
```
|
||||
|
||||
## Expand / Collapse
|
||||
|
||||
```csharp
|
||||
// Table will take up as much space as it can
|
||||
// with respect to other things.
|
||||
table.Expand();
|
||||
|
||||
// Table will take up minimal width
|
||||
table.Collapse();
|
||||
```
|
||||
|
||||
## Hide headers
|
||||
|
||||
```csharp
|
||||
// Hides all column headers
|
||||
table.HideHeaders();
|
||||
```
|
||||
|
||||
## Set table width
|
||||
|
||||
```csharp
|
||||
// Sets the table width to 50 cells
|
||||
table.SetWidth(50);
|
||||
```
|
||||
|
||||
# Column appearance
|
||||
|
||||
<!------------------------->
|
||||
<!--- COLUMN APPEARANCE --->
|
||||
<!------------------------->
|
||||
|
||||
## Alignment
|
||||
|
||||
```csharp
|
||||
// Set the alignment explicitly
|
||||
column.SetAlignment(Justify.Right);
|
||||
```
|
||||
|
||||
## Padding
|
||||
|
||||
```csharp
|
||||
// Set left and right padding
|
||||
column.SetPadding(left: 3, right: 5);
|
||||
|
||||
// Set padding individually.
|
||||
column.PadLeft(3);
|
||||
column.PadRight(5);
|
||||
```
|
||||
|
||||
## Disable column wrapping
|
||||
|
||||
```csharp
|
||||
// Disable column wrapping
|
||||
column.NoWrap();
|
||||
```
|
||||
|
||||
## Set column width
|
||||
|
||||
```csharp
|
||||
// Set the column width (no fluent extension method for this yet)
|
||||
column.Width = 15;
|
||||
```
|
||||
@@ -1,14 +1,20 @@
|
||||
namespace Docs
|
||||
namespace Docs
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const string NoContainer = nameof(NoContainer);
|
||||
public const string NoSidebar = nameof(NoSidebar);
|
||||
public const string NoLink = nameof(NoLink);
|
||||
public const string Topic = nameof(Topic);
|
||||
public const string EditLink = nameof(EditLink);
|
||||
public const string Description = nameof(Description);
|
||||
public const string Hidden = nameof(Hidden);
|
||||
|
||||
public static class Emojis
|
||||
{
|
||||
public const string Root = "EMOJIS_ROOT";
|
||||
}
|
||||
|
||||
public static class Colors
|
||||
{
|
||||
public const string Url = "https://raw.githubusercontent.com/spectresystems/spectre.console/main/resources/scripts/Generator/Data/colors.json";
|
||||
|
||||
7946
docs/src/Data/emojis.json
Normal file
7946
docs/src/Data/emojis.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
using Statiq.Common;
|
||||
using Statiq.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -16,6 +16,11 @@ namespace Docs
|
||||
return !document.GetBool(Constants.Hidden, false);
|
||||
}
|
||||
|
||||
public static bool ShowLink(this IDocument document)
|
||||
{
|
||||
return !document.GetBool(Constants.NoLink, false);
|
||||
}
|
||||
|
||||
public static IEnumerable<IDocument> OnlyVisible(this IEnumerable<IDocument> source)
|
||||
{
|
||||
return source.Where(x => x.IsVisible());
|
||||
|
||||
20
docs/src/Models/Emoji.cs
Normal file
20
docs/src/Models/Emoji.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Docs.Models
|
||||
{
|
||||
public sealed class Emoji
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Code { get; set; }
|
||||
|
||||
public static List<Emoji> Parse(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<List<Emoji>>(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
41
docs/src/Modules/ReadEmbedded.cs
Normal file
41
docs/src/Modules/ReadEmbedded.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Statiq.Common;
|
||||
|
||||
namespace Docs.Modules
|
||||
{
|
||||
public sealed class ReadEmbedded : Module
|
||||
{
|
||||
private readonly System.Reflection.Assembly _assembly;
|
||||
private readonly string _resource;
|
||||
|
||||
public ReadEmbedded(System.Reflection.Assembly assembly, string resource)
|
||||
{
|
||||
_assembly = assembly ?? throw new ArgumentNullException(nameof(assembly));
|
||||
_resource = resource ?? throw new ArgumentNullException(nameof(resource));
|
||||
}
|
||||
|
||||
protected override Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecutionContext context)
|
||||
{
|
||||
return Task.FromResult((IEnumerable<IDocument>)new[]
|
||||
{
|
||||
context.CreateDocument(ReadResource()),
|
||||
});
|
||||
}
|
||||
|
||||
private Stream ReadResource()
|
||||
{
|
||||
var resourceName = _resource.Replace("/", ".");
|
||||
|
||||
var stream = _assembly.GetManifestResourceStream(resourceName);
|
||||
if (stream == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not load manifest resource stream.");
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,8 @@ namespace Docs.Pipelines
|
||||
new ExecuteConfig(
|
||||
Config.FromDocument(async (doc, ctx) =>
|
||||
{
|
||||
var colors = Color.Parse(await doc.GetContentStringAsync()).ToList();
|
||||
var definitions = new List<IDocument> { colors.ToDocument(Constants.Colors.Root) };
|
||||
|
||||
return doc.Clone(new MetadataDictionary
|
||||
{
|
||||
[Constants.Colors.Root] = definitions
|
||||
});
|
||||
var data = Color.Parse(await doc.GetContentStringAsync()).ToList();
|
||||
return data.ToDocument(Constants.Colors.Root);
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
34
docs/src/Pipelines/EmojiPipeline.cs
Normal file
34
docs/src/Pipelines/EmojiPipeline.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using Docs.Models;
|
||||
using Docs.Modules;
|
||||
using Statiq.Common;
|
||||
using Statiq.Core;
|
||||
|
||||
namespace Docs.Pipelines
|
||||
{
|
||||
public class EmojiPipeline : Pipeline
|
||||
{
|
||||
public EmojiPipeline()
|
||||
{
|
||||
InputModules = new ModuleList
|
||||
{
|
||||
new ExecuteConfig(
|
||||
Config.FromContext(ctx => {
|
||||
return new ReadEmbedded(
|
||||
typeof(EmojiPipeline).Assembly,
|
||||
"Docs/src/Data/emojis.json");
|
||||
}))
|
||||
};
|
||||
|
||||
ProcessModules = new ModuleList
|
||||
{
|
||||
new ExecuteConfig(
|
||||
Config.FromDocument(async (doc, ctx) =>
|
||||
{
|
||||
var data = Emoji.Parse(await doc.GetContentStringAsync());
|
||||
return data.ToDocument(Constants.Emojis.Root);
|
||||
}))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,10 @@ namespace Docs.Shortcodes
|
||||
// Get the definition.
|
||||
var colors = context.Outputs
|
||||
.FromPipeline(nameof(ColorsPipeline))
|
||||
.First()
|
||||
.GetChildren(Constants.Colors.Root)
|
||||
.OfType<ObjectDocument<List<Color>>>()
|
||||
.First().Object;
|
||||
|
||||
// Headers
|
||||
var table = new XElement("table", new XAttribute("class", "table"));
|
||||
var header = new XElement("tr", new XAttribute("class", "color-row"));
|
||||
header.Add(new XElement("th", ""));
|
||||
|
||||
45
docs/src/Shortcodes/EmojiTableShortcode.cs
Normal file
45
docs/src/Shortcodes/EmojiTableShortcode.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Statiq.Common;
|
||||
using System.Xml.Linq;
|
||||
using Docs.Pipelines;
|
||||
using Docs.Models;
|
||||
|
||||
namespace Docs.Shortcodes
|
||||
{
|
||||
public class EmojiTableShortcode : SyncShortcode
|
||||
{
|
||||
public override ShortcodeResult Execute(KeyValuePair<string, string>[] args, string content, IDocument document, IExecutionContext context)
|
||||
{
|
||||
var emojis = context.Outputs
|
||||
.FromPipeline(nameof(EmojiPipeline))
|
||||
.OfType<ObjectDocument<List<Emoji>>>()
|
||||
.First().Object;
|
||||
|
||||
// Headers
|
||||
var table = new XElement("table", new XAttribute("class", "table"));
|
||||
var header = new XElement("tr", new XAttribute("class", "emoji-row"));
|
||||
header.Add(new XElement("th", ""));
|
||||
header.Add(new XElement("th", "Markup"));
|
||||
header.Add(new XElement("th", "Constant"));
|
||||
table.Add(header);
|
||||
|
||||
foreach (var emoji in emojis)
|
||||
{
|
||||
var code = emoji.Code.Replace("U+0000", "U+").Replace("U+000", "U+");
|
||||
var icon = string.Format("&#x{0};", emoji.Code.Replace("U+", string.Empty));
|
||||
|
||||
var row = new XElement("tr");
|
||||
row.Add(new XElement("td", icon));
|
||||
row.Add(new XElement("td", new XElement("code", $":{emoji.Id}:")));
|
||||
row.Add(new XElement("td", new XElement("code", emoji.Name)));
|
||||
|
||||
table.Add(row);
|
||||
}
|
||||
|
||||
return table.ToString()
|
||||
.Replace("&#x", "&#x");
|
||||
}
|
||||
}
|
||||
}
|
||||
14
examples/Borders/Borders.csproj
Normal file
14
examples/Borders/Borders.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Description>Demonstrates the different kind of borders.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
47
examples/Borders/Program.cs
Normal file
47
examples/Borders/Program.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Borders
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var items = new[]
|
||||
{
|
||||
Create("Ascii", Border.Ascii),
|
||||
Create("Ascii2", Border.Ascii2),
|
||||
Create("AsciiDoubleHead", Border.AsciiDoubleHead),
|
||||
Create("Horizontal", Border.Horizontal),
|
||||
Create("Simple", Border.Simple),
|
||||
Create("SimpleHeavy", Border.SimpleHeavy),
|
||||
Create("Minimal", Border.Minimal),
|
||||
Create("MinimalHeavyHead", Border.MinimalHeavyHead),
|
||||
Create("MinimalDoubleHead", Border.MinimalDoubleHead),
|
||||
Create("Square", Border.Square),
|
||||
Create("Rounded", Border.Rounded),
|
||||
Create("Heavy", Border.Heavy),
|
||||
Create("HeavyEdge", Border.HeavyEdge),
|
||||
Create("HeavyHead", Border.HeavyHead),
|
||||
Create("Double", Border.Double),
|
||||
Create("DoubleEdge", Border.DoubleEdge),
|
||||
};
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(new Columns(items).Collapse());
|
||||
}
|
||||
|
||||
private static IRenderable Create(string name, Border border)
|
||||
{
|
||||
var table = new Table().SetBorder(border);
|
||||
table.AddColumns("[yellow]Header 1[/]", "[yellow]Header 2[/]");
|
||||
table.AddRow("Cell", "Cell");
|
||||
table.AddRow("Cell", "Cell");
|
||||
|
||||
return new Panel(table)
|
||||
.SetHeader($" {name} ", Style.Parse("blue"), Justify.Center)
|
||||
.SetBorderStyle(Style.Parse("grey"))
|
||||
.NoBorder();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Description>Demonstrates how to render data into columns.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace ColumnsExample
|
||||
{
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Diagnostic
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
AnsiConsole.MarkupLine("Color system: [bold]{0}[/]", AnsiConsole.Capabilities.ColorSystem);
|
||||
AnsiConsole.MarkupLine("Supports ansi? [bold]{0}[/]", AnsiConsole.Capabilities.SupportsAnsi);
|
||||
AnsiConsole.MarkupLine("Legacy console? [bold]{0}[/]", AnsiConsole.Capabilities.LegacyConsole);
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("Buffer width: [bold]{0}[/]", AnsiConsole.Console.Width);
|
||||
AnsiConsole.MarkupLine("Buffer height: [bold]{0}[/]", AnsiConsole.Console.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
examples/Emojis/Emojis.csproj
Normal file
14
examples/Emojis/Emojis.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Description>Demonstrates how to render emojis.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
17
examples/Emojis/Program.cs
Normal file
17
examples/Emojis/Program.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Emojis
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Markup
|
||||
AnsiConsole.Render(
|
||||
new Panel("[yellow]Hello :globe_showing_europe_africa:![/]")
|
||||
.RoundedBorder()
|
||||
.SetHeader("Markup"));
|
||||
}
|
||||
}
|
||||
}
|
||||
27
examples/Info/Program.cs
Normal file
27
examples/Info/Program.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Info
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var grid = new Grid()
|
||||
.AddColumn(new GridColumn().NoWrap().PadRight(4))
|
||||
.AddColumn()
|
||||
.AddRow("[b]:artist_palette: Color system[/]", $"{AnsiConsole.Capabilities.ColorSystem}")
|
||||
.AddRow("[b]:nail_polish: Supports ansi?[/]", $"{GetEmoji(AnsiConsole.Capabilities.SupportsAnsi)}")
|
||||
.AddRow("[b]:top_hat: Legacy console?[/]", $"{GetEmoji(AnsiConsole.Capabilities.LegacyConsole)}")
|
||||
.AddRow("[b]:left_right_arrow: Buffer width[/]", $"{AnsiConsole.Console.Width}")
|
||||
.AddRow("[b]:up_down_arrow: Buffer height[/]", $"{AnsiConsole.Console.Height}");
|
||||
|
||||
AnsiConsole.Render(
|
||||
new Panel(grid)
|
||||
.SetHeader("Information"));
|
||||
}
|
||||
|
||||
private static string GetEmoji(bool value) => value
|
||||
? ":thumbs_up:"
|
||||
: ":thumbs_down:";
|
||||
}
|
||||
}
|
||||
14
examples/Links/Links.csproj
Normal file
14
examples/Links/Links.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Description>Demonstrates how to render links in a console.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
21
examples/Links/Program.cs
Normal file
21
examples/Links/Program.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Links
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
if (AnsiConsole.Capabilities.SupportLinks)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[link=https://patriksvensson.se]Click to visit my blog[/]!");
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]It looks like your terminal doesn't support links[/]");
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[yellow](╯°□°)╯[/]︵ [blue]┻━┻[/]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace PanelExample
|
||||
{
|
||||
@@ -14,7 +13,7 @@ namespace PanelExample
|
||||
AnsiConsole.Render(
|
||||
new Panel(
|
||||
new Panel(content)
|
||||
.SetBorderKind(BorderKind.Rounded)));
|
||||
.SetBorder(Border.Rounded)));
|
||||
|
||||
// Left adjusted panel with text
|
||||
AnsiConsole.Render(
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace TableExample
|
||||
private static void RenderBigTable()
|
||||
{
|
||||
// Create the table.
|
||||
var table = new Table().SetBorderKind(BorderKind.Rounded);
|
||||
var table = new Table().SetBorder(Border.Rounded);
|
||||
table.AddColumn("[red underline]Foo[/]");
|
||||
table.AddColumn(new TableColumn("[blue]Bar[/]") { Alignment = Justify.Right, NoWrap = true });
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace TableExample
|
||||
private static void RenderNestedTable()
|
||||
{
|
||||
// Create simple table.
|
||||
var simple = new Table().SetBorderKind(BorderKind.Rounded).SetBorderColor(Color.Red);
|
||||
var simple = new Table().SetBorder(Border.Rounded).SetBorderColor(Color.Red);
|
||||
simple.AddColumn(new TableColumn("[u]Foo[/]").Centered());
|
||||
simple.AddColumn(new TableColumn("[u]Bar[/]"));
|
||||
simple.AddColumn(new TableColumn("[u]Baz[/]"));
|
||||
@@ -66,7 +66,7 @@ namespace TableExample
|
||||
simple.AddRow("[blue]Hej[/]", "[yellow]Världen![/]", "");
|
||||
|
||||
// Create other table.
|
||||
var second = new Table().SetBorderKind(BorderKind.Square).SetBorderColor(Color.Green);
|
||||
var second = new Table().SetBorder(Border.Square).SetBorderColor(Color.Green);
|
||||
second.AddColumn(new TableColumn("[u]Foo[/]"));
|
||||
second.AddColumn(new TableColumn("[u]Bar[/]"));
|
||||
second.AddColumn(new TableColumn("[u]Baz[/]"));
|
||||
@@ -74,7 +74,7 @@ namespace TableExample
|
||||
second.AddRow(simple, new Text("Whaaat"), new Text("Lolz"));
|
||||
second.AddRow("[blue]Hej[/]", "[yellow]Världen![/]", "");
|
||||
|
||||
var table = new Table().SetBorderKind(BorderKind.Rounded);
|
||||
var table = new Table().SetBorder(Border.Rounded);
|
||||
table.AddColumn(new TableColumn(new Panel("[u]Foo[/]").SetBorderColor(Color.Red)));
|
||||
table.AddColumn(new TableColumn(new Panel("[u]Bar[/]").SetBorderColor(Color.Green)));
|
||||
table.AddColumn(new TableColumn(new Panel("[u]Baz[/]").SetBorderColor(Color.Blue)));
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
##########################################################
|
||||
|
||||
$Output = Join-Path $PSScriptRoot "Temp"
|
||||
$Source = Join-Path $PSScriptRoot "/../src/Spectre.Console"
|
||||
$Source = Join-Path $PSScriptRoot "/../../src/Spectre.Console"
|
||||
|
||||
if(!(Test-Path $Output -PathType Container)) {
|
||||
New-Item -ItemType Directory -Path $Output | Out-Null
|
||||
|
||||
24
resources/scripts/Generate-Emoji.ps1
Normal file
24
resources/scripts/Generate-Emoji.ps1
Normal file
@@ -0,0 +1,24 @@
|
||||
##########################################################
|
||||
# Script that generates the emoji lookup table.
|
||||
##########################################################
|
||||
|
||||
$Output = Join-Path $PSScriptRoot "Temp"
|
||||
$Source = Join-Path $PSScriptRoot "/../../src/Spectre.Console"
|
||||
$Docs = Join-Path $PSScriptRoot "/../../docs/src/Data"
|
||||
|
||||
if(!(Test-Path $Output -PathType Container)) {
|
||||
New-Item -ItemType Directory -Path $Output | Out-Null
|
||||
}
|
||||
|
||||
# Generate the files
|
||||
Push-Location Generator
|
||||
&dotnet run -- emoji "$Output" --input $Output
|
||||
if(!$?) {
|
||||
Pop-Location
|
||||
Throw "An error occured when generating code."
|
||||
}
|
||||
Pop-Location
|
||||
|
||||
# Copy the files to the correct location
|
||||
Copy-Item (Join-Path "$Output" "Emoji.Generated.cs") -Destination "$Source/Emoji.Generated.cs"
|
||||
Copy-Item (Join-Path "$Output" "emojis.json") -Destination "$Docs/emojis.json"
|
||||
@@ -55,5 +55,8 @@ namespace Generator.Commands
|
||||
{
|
||||
[CommandArgument(0, "<OUTPUT>")]
|
||||
public string Output { get; set; }
|
||||
|
||||
[CommandOption("-i|--input <PATH>")]
|
||||
public string Input { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
101
resources/scripts/Generator/Commands/EmojiGeneratorCommand.cs
Normal file
101
resources/scripts/Generator/Commands/EmojiGeneratorCommand.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Html.Parser;
|
||||
using Generator.Models;
|
||||
using Scriban;
|
||||
using Scriban.Runtime;
|
||||
using Spectre.Cli;
|
||||
using Spectre.IO;
|
||||
using Path = Spectre.IO.Path;
|
||||
using SpectreEnvironment = Spectre.IO.Environment;
|
||||
|
||||
namespace Generator.Commands
|
||||
{
|
||||
public sealed class EmojiGeneratorCommand : AsyncCommand<GeneratorCommandSettings>
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IEnvironment _environment;
|
||||
private readonly IHtmlParser _parser;
|
||||
|
||||
private readonly Dictionary<string, string> _templates = new Dictionary<string, string>
|
||||
{
|
||||
{ "Templates/Emoji.Generated.template", "Emoji.Generated.cs" },
|
||||
{ "Templates/Emoji.Json.template", "emojis.json" },
|
||||
};
|
||||
|
||||
public EmojiGeneratorCommand()
|
||||
{
|
||||
_fileSystem = new FileSystem();
|
||||
_environment = new SpectreEnvironment();
|
||||
_parser = new HtmlParser();
|
||||
}
|
||||
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, GeneratorCommandSettings settings)
|
||||
{
|
||||
var output = new DirectoryPath(settings.Output);
|
||||
if (!_fileSystem.Directory.Exists(settings.Output))
|
||||
{
|
||||
_fileSystem.Directory.Create(settings.Output);
|
||||
}
|
||||
|
||||
var stream = await FetchEmojis(settings);
|
||||
var document = await _parser.ParseDocumentAsync(stream);
|
||||
var emojis = Emoji.Parse(document).OrderBy(x => x.Name)
|
||||
.Where(emoji => !emoji.HasCombinators)
|
||||
.ToList();
|
||||
|
||||
// Render all templates
|
||||
foreach (var (templateFilename, outputFilename) in _templates)
|
||||
{
|
||||
var result = await RenderTemplate(new FilePath(templateFilename), emojis);
|
||||
|
||||
var outputPath = output.CombineWithFilePath(outputFilename);
|
||||
await File.WriteAllTextAsync(outputPath.FullPath, result);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private async Task<Stream> FetchEmojis(GeneratorCommandSettings settings)
|
||||
{
|
||||
var input = string.IsNullOrEmpty(settings.Input)
|
||||
? _environment.WorkingDirectory
|
||||
: new DirectoryPath(settings.Input);
|
||||
|
||||
var file = _fileSystem.File.Retrieve(input.CombineWithFilePath("emoji-list.html"));
|
||||
if (!file.Exists)
|
||||
{
|
||||
using var http = new HttpClient();
|
||||
using var httpStream = await http.GetStreamAsync("http://www.unicode.org/emoji/charts/emoji-list.html");
|
||||
using var outStream = file.OpenWrite();
|
||||
|
||||
await httpStream.CopyToAsync(outStream);
|
||||
}
|
||||
|
||||
return file.OpenRead();
|
||||
}
|
||||
|
||||
private static async Task<string> RenderTemplate(Path path, IReadOnlyCollection<Emoji> emojis)
|
||||
{
|
||||
var text = await File.ReadAllTextAsync(path.FullPath);
|
||||
|
||||
var template = Template.Parse(text);
|
||||
var templateContext = new TemplateContext
|
||||
{
|
||||
// Because of the insane amount of Emojis,
|
||||
// we need to get rid of some secure defaults :P
|
||||
LoopLimit = int.MaxValue,
|
||||
};
|
||||
|
||||
var scriptObject = new ScriptObject();
|
||||
scriptObject.Import(new { Emojis = emojis });
|
||||
templateContext.PushGlobal(scriptObject);
|
||||
|
||||
return await template.RenderAsync(templateContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,17 @@
|
||||
<None Update="Templates\ColorPalette.Generated.template">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\Emoji.Json.template">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\Emoji.Generated.template">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AngleSharp" Version="0.14.0" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Scriban" Version="2.1.3" />
|
||||
<PackageReference Include="Spectre.Cli" Version="0.36.1-preview.0.6" />
|
||||
|
||||
95
resources/scripts/Generator/Models/Emoji.cs
Normal file
95
resources/scripts/Generator/Models/Emoji.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AngleSharp.Dom;
|
||||
using AngleSharp.Html.Dom;
|
||||
using Humanizer;
|
||||
|
||||
namespace Generator.Models
|
||||
{
|
||||
public class Emoji
|
||||
{
|
||||
private static readonly string[] _headers = { "count", "code", "sample", "name" };
|
||||
|
||||
private Emoji(string identifier, string name, string code, string description)
|
||||
{
|
||||
Identifier = identifier;
|
||||
Name = name;
|
||||
Code = code;
|
||||
Description = description;
|
||||
NormalizedCode = Code.Replace("\\U", "U+");
|
||||
HasCombinators = Code.Split(new[] { "\\U" }, System.StringSplitOptions.RemoveEmptyEntries).Length > 1;
|
||||
}
|
||||
|
||||
public string Identifier { get; set; }
|
||||
public string Code { get; }
|
||||
public string NormalizedCode { get; }
|
||||
public string Name { get; }
|
||||
public string Description { get; set; }
|
||||
public bool HasCombinators { get; set; }
|
||||
|
||||
public static IEnumerable<Emoji> Parse(IHtmlDocument document)
|
||||
{
|
||||
var rows = document
|
||||
.GetNodes<IHtmlTableRowElement>(predicate: row =>
|
||||
row.Cells.Length >= _headers.Length && // Filter out rows that don't have enough cells.
|
||||
row.Cells.All(x => x.LocalName == TagNames.Td)); // We're only interested in td cells, not th.
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var dictionary = _headers
|
||||
.Zip(row.Cells, (header, cell) => (Header: header, cell.TextContent.Trim()))
|
||||
.ToDictionary(x => x.Item1, x => x.Item2);
|
||||
|
||||
var code = TransformCode(dictionary["code"]);
|
||||
var identifier = TransformName(dictionary["name"])
|
||||
.Replace("-", "_")
|
||||
.Replace("(", string.Empty)
|
||||
.Replace(")", string.Empty);
|
||||
|
||||
var description = dictionary["name"].Humanize();
|
||||
|
||||
var name = identifier
|
||||
.Replace("1st", "first")
|
||||
.Replace("2nd", "second")
|
||||
.Replace("3rd", "third")
|
||||
.Pascalize();
|
||||
|
||||
yield return new Emoji(identifier, name, code, description);
|
||||
}
|
||||
}
|
||||
|
||||
private static string TransformName(string name)
|
||||
{
|
||||
return name.Replace(":", string.Empty)
|
||||
.Replace(",", string.Empty)
|
||||
.Replace(".", string.Empty)
|
||||
.Replace("\u201c", string.Empty)
|
||||
.Replace("\u201d", string.Empty)
|
||||
.Replace("\u229b", string.Empty)
|
||||
.Replace(' ', '_')
|
||||
.Replace("’s", "s")
|
||||
.Replace("’", "_")
|
||||
.Replace("&", "and")
|
||||
.Replace("#", "hash")
|
||||
.Replace("*", "star")
|
||||
.Replace("!", string.Empty)
|
||||
.Trim()
|
||||
.ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static string TransformCode(string code)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
foreach (var part in code.Split(' '))
|
||||
{
|
||||
builder.Append(part.Length == 6
|
||||
? part.Replace("+", "0000")
|
||||
: part.Replace("+", "000"));
|
||||
}
|
||||
|
||||
return builder.ToString().Replace("U", "\\U");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace Generator
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.AddCommand<ColorGeneratorCommand>("colors");
|
||||
config.AddCommand<EmojiGeneratorCommand>("emoji");
|
||||
});
|
||||
|
||||
return app.Run(args);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Generated {{ date.now | date.to_string `%Y-%m-%d %k:%M` }}
|
||||
// Generated {{ date.now | date.to_string `%F %R` }}
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Generated {{ date.now | date.to_string `%Y-%m-%d %k:%M` }}
|
||||
// Generated {{ date.now | date.to_string `%F %R` }}
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Generated {{ date.now | date.to_string `%Y-%m-%d %k:%M` }}
|
||||
// Generated {{ date.now | date.to_string `%F %R` }}
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Generated {{ date.now | date.to_string `%F %R` }}
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility for working with emojis.
|
||||
/// </summary>
|
||||
public static partial class Emoji
|
||||
{
|
||||
private static readonly Dictionary<string, string> _emojis
|
||||
= new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
|
||||
{
|
||||
{{~ for emoji in emojis ~}}
|
||||
{ "{{ emoji.identifier }}", Emoji.Known.{{ emoji.name }} },
|
||||
{{~ end ~}}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Contains all predefined emojis.
|
||||
/// </summary>
|
||||
public static class Known
|
||||
{
|
||||
{{- for emoji in emojis }}
|
||||
/// <summary>
|
||||
/// Gets the "{{ emoji.identifier }}" emoji.
|
||||
/// Description: {{ emoji.description }}.
|
||||
/// </summary>
|
||||
public const string {{ emoji.name }} = "{{ emoji.code }}";
|
||||
{{~ end ~}}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
resources/scripts/Generator/Templates/Emoji.Json.template
Normal file
10
resources/scripts/Generator/Templates/Emoji.Json.template
Normal file
@@ -0,0 +1,10 @@
|
||||
[
|
||||
{{~ for x in 0..(emojis.size-1) ~}}
|
||||
{
|
||||
"id": "{{ emojis[x].identifier }}",
|
||||
"name": "{{ emojis[x].name }}",
|
||||
"description": "{{ emojis[x].description }}",
|
||||
"code": "{{ emojis[x].normalized_code }}"
|
||||
}{{ if x != (emojis.size-1) }},{{ end }}
|
||||
{{~ end ~}}
|
||||
]
|
||||
@@ -42,7 +42,7 @@
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.113">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Roslynator.Analyzers" Version="2.3.0">
|
||||
<PackageReference Include="Roslynator.Analyzers" Version="3.0.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Tests
|
||||
{
|
||||
public static class ConsoleExtensions
|
||||
{
|
||||
public static void SetColor(this IAnsiConsole console, Color color, bool foreground)
|
||||
{
|
||||
if (console is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(console));
|
||||
}
|
||||
|
||||
if (foreground)
|
||||
{
|
||||
console.Foreground = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.Background = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/Spectre.Console.Tests/Extensions/StyleExtensions.cs
Normal file
15
src/Spectre.Console.Tests/Extensions/StyleExtensions.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Spectre.Console.Tests
|
||||
{
|
||||
internal static class StyleExtensions
|
||||
{
|
||||
public static Style SetColor(this Style style, Color color, bool foreground)
|
||||
{
|
||||
if (foreground)
|
||||
{
|
||||
return style.WithForeground(color);
|
||||
}
|
||||
|
||||
return style.WithBackground(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Spectre.Console.Tests
|
||||
{
|
||||
public sealed class AnsiConsoleFixture : IDisposable
|
||||
{
|
||||
private readonly StringWriter _writer;
|
||||
|
||||
public IAnsiConsole Console { get; }
|
||||
|
||||
public string Output => _writer.ToString();
|
||||
|
||||
public AnsiConsoleFixture(ColorSystem system, AnsiSupport ansi = AnsiSupport.Yes, int width = 80)
|
||||
{
|
||||
_writer = new StringWriter();
|
||||
|
||||
Console = new ConsoleWithWidth(
|
||||
AnsiConsole.Create(new AnsiConsoleSettings
|
||||
{
|
||||
Ansi = ansi,
|
||||
ColorSystem = (ColorSystemSupport)system,
|
||||
Out = _writer,
|
||||
}), width);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_writer?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Spectre.Console.Tests
|
||||
{
|
||||
public sealed class ConsoleWithWidth : IAnsiConsole
|
||||
{
|
||||
private readonly IAnsiConsole _console;
|
||||
|
||||
public Capabilities Capabilities => _console.Capabilities;
|
||||
|
||||
public int Width { get; }
|
||||
public int Height => _console.Height;
|
||||
|
||||
public Encoding Encoding => _console.Encoding;
|
||||
|
||||
public Decoration Decoration { get => _console.Decoration; set => _console.Decoration = value; }
|
||||
public Color Foreground { get => _console.Foreground; set => _console.Foreground = value; }
|
||||
public Color Background { get => _console.Background; set => _console.Background = value; }
|
||||
|
||||
public ConsoleWithWidth(IAnsiConsole console, int width)
|
||||
{
|
||||
_console = console;
|
||||
Width = width;
|
||||
}
|
||||
|
||||
public void Write(string text)
|
||||
{
|
||||
_console.Write(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
src/Spectre.Console.Tests/Tools/AnsiConsoleFixture.cs
Normal file
45
src/Spectre.Console.Tests/Tools/AnsiConsoleFixture.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Spectre.Console.Rendering;
|
||||
using Spectre.Console.Tests.Tools;
|
||||
|
||||
namespace Spectre.Console.Tests
|
||||
{
|
||||
public sealed class TestableAnsiConsole : IDisposable, IAnsiConsole
|
||||
{
|
||||
private readonly StringWriter _writer;
|
||||
private readonly IAnsiConsole _console;
|
||||
|
||||
public string Output => _writer.ToString();
|
||||
|
||||
public Capabilities Capabilities => _console.Capabilities;
|
||||
public Encoding Encoding => _console.Encoding;
|
||||
public int Width { get; }
|
||||
public int Height => _console.Height;
|
||||
|
||||
public TestableAnsiConsole(ColorSystem system, AnsiSupport ansi = AnsiSupport.Yes, int width = 80)
|
||||
{
|
||||
_writer = new StringWriter();
|
||||
_console = AnsiConsole.Create(new AnsiConsoleSettings
|
||||
{
|
||||
Ansi = ansi,
|
||||
ColorSystem = (ColorSystemSupport)system,
|
||||
Out = _writer,
|
||||
LinkIdentityGenerator = new TestLinkIdentityGenerator(),
|
||||
});
|
||||
|
||||
Width = width;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_writer?.Dispose();
|
||||
}
|
||||
|
||||
public void Write(Segment segment)
|
||||
{
|
||||
_console.Write(segment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console.Tests
|
||||
{
|
||||
@@ -16,6 +17,7 @@ namespace Spectre.Console.Tests
|
||||
public Decoration Decoration { get; set; }
|
||||
public Color Foreground { get; set; }
|
||||
public Color Background { get; set; }
|
||||
public string Link { get; set; }
|
||||
|
||||
public StringWriter Writer { get; }
|
||||
public string RawOutput => Writer.ToString();
|
||||
@@ -39,9 +41,14 @@ namespace Spectre.Console.Tests
|
||||
Writer.Dispose();
|
||||
}
|
||||
|
||||
public void Write(string text)
|
||||
public void Write(Segment segment)
|
||||
{
|
||||
Writer.Write(text);
|
||||
if (segment is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(segment));
|
||||
}
|
||||
|
||||
Writer.Write(segment.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/Spectre.Console.Tests/Tools/TestLinkIdentityGenerator.cs
Normal file
10
src/Spectre.Console.Tests/Tools/TestLinkIdentityGenerator.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Spectre.Console.Tests.Tools
|
||||
{
|
||||
public sealed class TestLinkIdentityGenerator : ILinkIdentityGenerator
|
||||
{
|
||||
public int GenerateId(string link, string text)
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Code(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.TrueColor);
|
||||
fixture.Console.SetColor(new Color(128, 0, 128), foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.TrueColor);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(new Color(128, 0, 128), foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -29,14 +28,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Eight_Bit_Ansi_Code_For_Known_Colors(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.TrueColor);
|
||||
fixture.Console.SetColor(Color.Purple, foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.TrueColor);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(Color.Purple, foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,14 +46,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.EightBit);
|
||||
fixture.Console.SetColor(Color.Olive, foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.EightBit);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(Color.Olive, foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -64,14 +61,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Map_TrueColor_To_Nearest_Eight_Bit_Color_If_Possible(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.EightBit);
|
||||
fixture.Console.SetColor(new Color(128, 128, 0), foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.EightBit);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(new Color(128, 128, 0), foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -80,14 +76,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Estimate_TrueColor_To_Nearest_Eight_Bit_Color(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.EightBit);
|
||||
fixture.Console.SetColor(new Color(126, 127, 0), foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.EightBit);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(new Color(126, 127, 0), foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,14 +94,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard);
|
||||
fixture.Console.SetColor(Color.Olive, foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(Color.Olive, foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -120,14 +114,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard);
|
||||
fixture.Console.SetColor(new Color(r, g, b), foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -141,14 +134,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard);
|
||||
fixture.Console.SetColor(new Color(r, g, b), foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,14 +152,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Legacy);
|
||||
fixture.Console.SetColor(Color.Olive, foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Legacy);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(Color.Olive, foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -181,14 +172,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Legacy);
|
||||
fixture.Console.SetColor(new Color(r, g, b), foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Legacy);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -202,14 +192,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Legacy);
|
||||
fixture.Console.SetColor(new Color(r, g, b), foreground);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Legacy);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,18 @@ namespace Spectre.Console.Tests.Unit
|
||||
[Theory]
|
||||
[InlineData("[yellow]Hello[/]", "[93mHello[0m")]
|
||||
[InlineData("[yellow]Hello [italic]World[/]![/]", "[93mHello [0m[3;93mWorld[0m[93m![0m")]
|
||||
[InlineData("[link=https://patriksvensson.se]Click to visit my blog[/]", "]8;id=1024;https://patriksvensson.se\\Click to visit my blog]8;;\\")]
|
||||
[InlineData("[link]https://patriksvensson.se[/]", "]8;id=1024;https://patriksvensson.se\\https://patriksvensson.se]8;;\\")]
|
||||
public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
|
||||
// When
|
||||
fixture.Console.Markup(markup);
|
||||
console.Markup(markup);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -30,13 +32,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Be_Able_To_Escape_Tags(string markup, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
|
||||
// When
|
||||
fixture.Console.Markup(markup);
|
||||
console.Markup(markup);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -47,10 +49,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => fixture.Console.Markup(markup));
|
||||
var result = Record.Exception(() => console.Markup(markup));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<InvalidOperationException>()
|
||||
@@ -61,10 +63,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Tags_Are_Unbalanced()
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => fixture.Console.Markup("[yellow][blue]Hello[/]"));
|
||||
var result = Record.Exception(() => console.Markup("[yellow][blue]Hello[/]"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<InvalidOperationException>()
|
||||
@@ -75,10 +77,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Encounters_Closing_Tag()
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => fixture.Console.Markup("Hello[/]World"));
|
||||
var result = Record.Exception(() => console.Markup("Hello[/]World"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<InvalidOperationException>()
|
||||
|
||||
@@ -18,14 +18,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Write_Decorated_Text_Correctly(Decoration decoration, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.TrueColor);
|
||||
fixture.Console.Decoration = decoration;
|
||||
var console = new TestableAnsiConsole(ColorSystem.TrueColor);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello World");
|
||||
console.Write("Hello World", Style.WithDecoration(decoration));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -34,14 +33,13 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Write_Text_With_Multiple_Decorations_Correctly(Decoration decoration, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.TrueColor);
|
||||
fixture.Console.Decoration = decoration;
|
||||
var console = new TestableAnsiConsole(ColorSystem.TrueColor);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello World");
|
||||
console.Write("Hello World", Style.WithDecoration(decoration));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe(expected);
|
||||
console.Output.ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
@@ -11,237 +10,68 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Combine_Decoration_And_Colors()
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard);
|
||||
fixture.Console.Foreground = Color.RoyalBlue1;
|
||||
fixture.Console.Background = Color.NavajoWhite1;
|
||||
fixture.Console.Decoration = Decoration.Italic;
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write(
|
||||
"Hello",
|
||||
Style.WithForeground(Color.RoyalBlue1)
|
||||
.WithBackground(Color.NavajoWhite1)
|
||||
.WithDecoration(Decoration.Italic));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("\u001b[3;90;47mHello\u001b[0m");
|
||||
console.Output.ShouldBe("\u001b[3;90;47mHello\u001b[0m");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Include_Foreground_If_Set_To_Default_Color()
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard);
|
||||
fixture.Console.Foreground = Color.Default;
|
||||
fixture.Console.Background = Color.NavajoWhite1;
|
||||
fixture.Console.Decoration = Decoration.Italic;
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write(
|
||||
"Hello",
|
||||
Style.WithForeground(Color.Default)
|
||||
.WithBackground(Color.NavajoWhite1)
|
||||
.WithDecoration(Decoration.Italic));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("\u001b[3;47mHello\u001b[0m");
|
||||
console.Output.ShouldBe("\u001b[3;47mHello\u001b[0m");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Include_Background_If_Set_To_Default_Color()
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard);
|
||||
fixture.Console.Foreground = Color.RoyalBlue1;
|
||||
fixture.Console.Background = Color.Default;
|
||||
fixture.Console.Decoration = Decoration.Italic;
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write(
|
||||
"Hello",
|
||||
Style.WithForeground(Color.RoyalBlue1)
|
||||
.WithBackground(Color.Default)
|
||||
.WithDecoration(Decoration.Italic));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("\u001b[3;90mHello\u001b[0m");
|
||||
console.Output.ShouldBe("\u001b[3;90mHello\u001b[0m");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Include_Decoration_If_Set_To_None()
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard);
|
||||
fixture.Console.Foreground = Color.RoyalBlue1;
|
||||
fixture.Console.Background = Color.NavajoWhite1;
|
||||
fixture.Console.Decoration = Decoration.None;
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard);
|
||||
|
||||
// When
|
||||
fixture.Console.Write("Hello");
|
||||
console.Write(
|
||||
"Hello",
|
||||
Style.WithForeground(Color.RoyalBlue1)
|
||||
.WithBackground(Color.NavajoWhite1)
|
||||
.WithDecoration(Decoration.None));
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("\u001b[90;47mHello\u001b[0m");
|
||||
}
|
||||
|
||||
public sealed class Write
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Int32_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, 32);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_UInt32_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, 32U);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Int64_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, 32L);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_UInt64_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, 32UL);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Single_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, 32.432F);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32.432");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Double_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, (double)32.432);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32.432");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Decimal_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, 32.432M);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32.432");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Boolean_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, true);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("True");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Char_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(CultureInfo.InvariantCulture, 'P');
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("P");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Char_Array_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(
|
||||
CultureInfo.InvariantCulture,
|
||||
new[] { 'P', 'a', 't', 'r', 'i', 'k' });
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("Patrik");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Formatted_String_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.Write(
|
||||
CultureInfo.InvariantCulture,
|
||||
"Hello {0}! {1}",
|
||||
"World", 32);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("Hello World! 32");
|
||||
}
|
||||
console.Output.ShouldBe("\u001b[90;47mHello\u001b[0m");
|
||||
}
|
||||
|
||||
public sealed class WriteLine
|
||||
@@ -250,16 +80,14 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Reset_Colors_Correctly_After_Line_Break()
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
|
||||
// When
|
||||
fixture.Console.Background = ConsoleColor.Red;
|
||||
fixture.Console.WriteLine("Hello");
|
||||
fixture.Console.Background = ConsoleColor.Green;
|
||||
fixture.Console.WriteLine("World");
|
||||
console.WriteLine("Hello", Style.WithBackground(ConsoleColor.Red));
|
||||
console.WriteLine("World", Style.WithBackground(ConsoleColor.Green));
|
||||
|
||||
// Then
|
||||
fixture.Output.NormalizeLineEndings()
|
||||
console.Output.NormalizeLineEndings()
|
||||
.ShouldBe("[101mHello[0m\n[102mWorld[0m\n");
|
||||
}
|
||||
|
||||
@@ -267,186 +95,15 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Reset_Colors_Correctly_After_Line_Break_In_Text()
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
|
||||
// When
|
||||
fixture.Console.Background = ConsoleColor.Red;
|
||||
fixture.Console.WriteLine("Hello\nWorld");
|
||||
console.WriteLine("Hello\nWorld", Style.WithBackground(ConsoleColor.Red));
|
||||
|
||||
// Then
|
||||
fixture.Output.NormalizeLineEndings()
|
||||
console.Output.NormalizeLineEndings()
|
||||
.ShouldBe("[101mHello[0m\n[101mWorld[0m\n");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Int32_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, 32);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_UInt32_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, 32U);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Int64_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, 32L);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_UInt64_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, 32UL);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Single_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, 32.432F);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32.432" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Double_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, (double)32.432);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32.432" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Decimal_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, 32.432M);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("32.432" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Boolean_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, true);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("True" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Char_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(CultureInfo.InvariantCulture, 'P');
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("P" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Char_Array_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(
|
||||
CultureInfo.InvariantCulture,
|
||||
new[] { 'P', 'a', 't', 'r', 'i', 'k' });
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("Patrik" + Environment.NewLine);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AnsiSupport.Yes)]
|
||||
[InlineData(AnsiSupport.No)]
|
||||
public void Should_Write_Formatted_String_With_Format_Provider(AnsiSupport ansi)
|
||||
{
|
||||
// Given
|
||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);
|
||||
|
||||
// When
|
||||
fixture.Console.WriteLine(
|
||||
CultureInfo.InvariantCulture,
|
||||
"Hello {0}! {1}",
|
||||
"World", 32);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("Hello World! 32" + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using Shouldly;
|
||||
using Spectre.Console.Rendering;
|
||||
using Xunit;
|
||||
@@ -7,35 +6,794 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
public sealed class BorderTests
|
||||
{
|
||||
public sealed class TheGetBorderMethod
|
||||
public sealed class NoBorder
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(BorderKind.None, false, typeof(NoBorder))]
|
||||
[InlineData(BorderKind.Ascii, false, typeof(AsciiBorder))]
|
||||
[InlineData(BorderKind.Square, false, typeof(SquareBorder))]
|
||||
[InlineData(BorderKind.Rounded, false, typeof(RoundedBorder))]
|
||||
[InlineData(BorderKind.None, true, typeof(NoBorder))]
|
||||
[InlineData(BorderKind.Ascii, true, typeof(AsciiBorder))]
|
||||
[InlineData(BorderKind.Square, true, typeof(SquareBorder))]
|
||||
[InlineData(BorderKind.Rounded, true, typeof(SquareBorder))]
|
||||
public void Should_Return_Correct_Border_For_Specified_Kind(BorderKind kind, bool safe, Type expected)
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var result = Border.GetBorder(kind, safe);
|
||||
var visibility = Border.None.Visible;
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType(expected);
|
||||
visibility.ShouldBeFalse();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.None.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.None);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Unknown_Border_Kind_Is_Specified()
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given, When
|
||||
var result = Record.Exception(() => Border.GetBorder((BorderKind)int.MaxValue, false));
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().NoBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<InvalidOperationException>();
|
||||
result.Message.ShouldBe("Unknown border kind");
|
||||
console.Lines.Count.ShouldBe(3);
|
||||
console.Lines[0].ShouldBe("Header 1 Header 2");
|
||||
console.Lines[1].ShouldBe("Cell Cell ");
|
||||
console.Lines[2].ShouldBe("Cell Cell ");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AsciiBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Ascii.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Ascii.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Ascii);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().AsciiBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("+---------------------+");
|
||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||
console.Lines[2].ShouldBe("|----------+----------|");
|
||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||
console.Lines[5].ShouldBe("+---------------------+");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Ascii2Border
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Ascii2.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Ascii2.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Ascii2);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().Ascii2Border();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("+----------+----------+");
|
||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||
console.Lines[2].ShouldBe("|----------+----------|");
|
||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||
console.Lines[5].ShouldBe("+----------+----------+");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AsciiDoubleHeadBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.AsciiDoubleHead.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.AsciiDoubleHead.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.AsciiDoubleHead);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().AsciiDoubleHeadBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("+----------+----------+");
|
||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||
console.Lines[2].ShouldBe("|==========+==========|");
|
||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||
console.Lines[5].ShouldBe("+----------+----------+");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SquareBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Square.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Square.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Square);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().SquareBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("┌──────────┬──────────┐");
|
||||
console.Lines[1].ShouldBe("│ Header 1 │ Header 2 │");
|
||||
console.Lines[2].ShouldBe("├──────────┼──────────┤");
|
||||
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
||||
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
||||
console.Lines[5].ShouldBe("└──────────┴──────────┘");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RoundedBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Rounded.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Rounded.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Square);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().RoundedBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("╭──────────┬──────────╮");
|
||||
console.Lines[1].ShouldBe("│ Header 1 │ Header 2 │");
|
||||
console.Lines[2].ShouldBe("├──────────┼──────────┤");
|
||||
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
||||
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
||||
console.Lines[5].ShouldBe("╰──────────┴──────────╯");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MinimalBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Minimal.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Minimal.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Minimal);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().MinimalBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe(" ");
|
||||
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
||||
console.Lines[2].ShouldBe(" ──────────┼────────── ");
|
||||
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
||||
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
||||
console.Lines[5].ShouldBe(" ");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MinimalHeavyHeadBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.MinimalHeavyHead.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.MinimalHeavyHead.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Minimal);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().MinimalHeavyHeadBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe(" ");
|
||||
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
||||
console.Lines[2].ShouldBe(" ━━━━━━━━━━┿━━━━━━━━━━ ");
|
||||
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
||||
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
||||
console.Lines[5].ShouldBe(" ");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MinimalDoubleHeadBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.MinimalDoubleHead.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.MinimalDoubleHead.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.MinimalDoubleHead);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().MinimalDoubleHeadBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe(" ");
|
||||
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
||||
console.Lines[2].ShouldBe(" ══════════╪══════════ ");
|
||||
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
||||
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
||||
console.Lines[5].ShouldBe(" ");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SimpleBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Simple.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Simple.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Simple);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().SimpleBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe(" ");
|
||||
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
||||
console.Lines[2].ShouldBe("───────────────────────");
|
||||
console.Lines[3].ShouldBe(" Cell Cell ");
|
||||
console.Lines[4].ShouldBe(" Cell Cell ");
|
||||
console.Lines[5].ShouldBe(" ");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HorizontalBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Horizontal.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Horizontal.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Horizontal);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().HorizontalBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("───────────────────────");
|
||||
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
||||
console.Lines[2].ShouldBe("───────────────────────");
|
||||
console.Lines[3].ShouldBe(" Cell Cell ");
|
||||
console.Lines[4].ShouldBe(" Cell Cell ");
|
||||
console.Lines[5].ShouldBe("───────────────────────");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SimpleHeavyBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.SimpleHeavy.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.SimpleHeavy.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Simple);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().SimpleHeavyBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe(" ");
|
||||
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
||||
console.Lines[2].ShouldBe("━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
console.Lines[3].ShouldBe(" Cell Cell ");
|
||||
console.Lines[4].ShouldBe(" Cell Cell ");
|
||||
console.Lines[5].ShouldBe(" ");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HeavyBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Heavy.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Heavy.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Square);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().HeavyBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("┏━━━━━━━━━━┳━━━━━━━━━━┓");
|
||||
console.Lines[1].ShouldBe("┃ Header 1 ┃ Header 2 ┃");
|
||||
console.Lines[2].ShouldBe("┣━━━━━━━━━━╋━━━━━━━━━━┫");
|
||||
console.Lines[3].ShouldBe("┃ Cell ┃ Cell ┃");
|
||||
console.Lines[4].ShouldBe("┃ Cell ┃ Cell ┃");
|
||||
console.Lines[5].ShouldBe("┗━━━━━━━━━━┻━━━━━━━━━━┛");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HeavyEdgeBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.HeavyEdge.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.HeavyEdge.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Square);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().HeavyEdgeBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("┏━━━━━━━━━━┯━━━━━━━━━━┓");
|
||||
console.Lines[1].ShouldBe("┃ Header 1 │ Header 2 ┃");
|
||||
console.Lines[2].ShouldBe("┠──────────┼──────────┨");
|
||||
console.Lines[3].ShouldBe("┃ Cell │ Cell ┃");
|
||||
console.Lines[4].ShouldBe("┃ Cell │ Cell ┃");
|
||||
console.Lines[5].ShouldBe("┗━━━━━━━━━━┷━━━━━━━━━━┛");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HeavyHeadBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.HeavyHead.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.HeavyHead.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Square);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().HeavyHeadBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("┏━━━━━━━━━━┳━━━━━━━━━━┓");
|
||||
console.Lines[1].ShouldBe("┃ Header 1 ┃ Header 2 ┃");
|
||||
console.Lines[2].ShouldBe("┡━━━━━━━━━━╇━━━━━━━━━━┩");
|
||||
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
||||
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
||||
console.Lines[5].ShouldBe("└──────────┴──────────┘");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DoubleBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.Double.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.Double.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.Double);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().DoubleBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("╔══════════╦══════════╗");
|
||||
console.Lines[1].ShouldBe("║ Header 1 ║ Header 2 ║");
|
||||
console.Lines[2].ShouldBe("╠══════════╬══════════╣");
|
||||
console.Lines[3].ShouldBe("║ Cell ║ Cell ║");
|
||||
console.Lines[4].ShouldBe("║ Cell ║ Cell ║");
|
||||
console.Lines[5].ShouldBe("╚══════════╩══════════╝");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DoubleEdgeBorder
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Visibility()
|
||||
{
|
||||
// Given, When
|
||||
var visibility = Border.DoubleEdge.Visible;
|
||||
|
||||
// Then
|
||||
visibility.ShouldBeTrue();
|
||||
}
|
||||
|
||||
public sealed class TheSafeGetBorderMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_Safe_Border()
|
||||
{
|
||||
// Given, When
|
||||
var border = Border.DoubleEdge.GetSafeBorder(safe: true);
|
||||
|
||||
// Then
|
||||
border.ShouldBeSameAs(Border.DoubleEdge);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var table = Fixture.GetTable().DoubleEdgeBorder();
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("╔══════════╤══════════╗");
|
||||
console.Lines[1].ShouldBe("║ Header 1 │ Header 2 ║");
|
||||
console.Lines[2].ShouldBe("╟──────────┼──────────╢");
|
||||
console.Lines[3].ShouldBe("║ Cell │ Cell ║");
|
||||
console.Lines[4].ShouldBe("║ Cell │ Cell ║");
|
||||
console.Lines[5].ShouldBe("╚══════════╧══════════╝");
|
||||
}
|
||||
}
|
||||
|
||||
private static class Fixture
|
||||
{
|
||||
public static Table GetTable()
|
||||
{
|
||||
var table = new Table();
|
||||
table.AddColumns("Header 1", "Header 2");
|
||||
table.AddRow("Cell", "Cell");
|
||||
table.AddRow("Cell", "Cell");
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
src/Spectre.Console.Tests/Unit/EmojiTests.cs
Normal file
44
src/Spectre.Console.Tests/Unit/EmojiTests.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
public sealed class EmojiTests
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Substitute_Emoji_Shortcodes_In_Markdown()
|
||||
{
|
||||
// Given
|
||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
|
||||
// When
|
||||
console.Markup("Hello :globe_showing_europe_africa:!");
|
||||
|
||||
// Then
|
||||
console.Output.ShouldBe("Hello 🌍!");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Contain_Predefined_Emojis()
|
||||
{
|
||||
// Given, When
|
||||
const string result = "Hello " + Emoji.Known.GlobeShowingEuropeAfrica + "!";
|
||||
|
||||
// Then
|
||||
result.ShouldBe("Hello 🌍!");
|
||||
}
|
||||
|
||||
public sealed class TheReplaceMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Replace_Emojis_In_Text()
|
||||
{
|
||||
// Given, When
|
||||
var result = Emoji.Replace("Hello :globe_showing_europe_africa:!");
|
||||
|
||||
// Then
|
||||
result.ShouldBe("Hello 🌍!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,9 +190,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
// Given
|
||||
var console = new PlainConsole(width: 80);
|
||||
var grid = new Grid();
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(3, 0) });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(0, 0) });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(0, 3) });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(3, 0, 0, 0) });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(0, 0, 0, 0) });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(0, 0, 3, 0) });
|
||||
grid.AddRow("Foo", "Bar", "Baz");
|
||||
grid.AddRow("Qux", "Corgi", "Waldo");
|
||||
grid.AddRow("Grault", "Garply", "Fred");
|
||||
@@ -213,7 +213,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
var console = new PlainConsole(width: 80);
|
||||
var grid = new Grid();
|
||||
grid.AddColumn(new GridColumn { NoWrap = true });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(2, 0) });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(2, 0, 0, 0) });
|
||||
grid.AddRow("[bold]Options[/]", string.Empty);
|
||||
grid.AddRow(" [blue]-h[/], [blue]--help[/]", "Show command line help.");
|
||||
grid.AddRow(" [blue]-c[/], [blue]--configuration[/]", "The configuration to run for.\nThe default for most projects is [green]Debug[/].");
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Closing_Tag_Is_Not_Properly_Escaped(string input)
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole();
|
||||
var console = new PlainConsole();
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => new Markup(input));
|
||||
@@ -27,14 +27,30 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Escape_Markup_Blocks_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole();
|
||||
var console = new PlainConsole();
|
||||
var markup = new Markup("Hello [[ World ]] !");
|
||||
|
||||
// When
|
||||
fixture.Render(markup);
|
||||
console.Render(markup);
|
||||
|
||||
// Then
|
||||
fixture.Output.ShouldBe("Hello [ World ] !");
|
||||
console.Output.ShouldBe("Hello [ World ] !");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Hello [link=http://example.com]example.com[/]", "Hello example.com")]
|
||||
[InlineData("Hello [link=http://example.com]http://example.com[/]", "Hello http://example.com")]
|
||||
public void Should_Render_Links_As_Expected(string input, string output)
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var markup = new Markup(input);
|
||||
|
||||
// When
|
||||
console.Render(markup);
|
||||
|
||||
// Then
|
||||
console.Output.ShouldBe(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
107
src/Spectre.Console.Tests/Unit/PadderTests.cs
Normal file
107
src/Spectre.Console.Tests/Unit/PadderTests.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
public sealed class PadderTests
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Render_Padded_Object_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 60);
|
||||
var table = new Table();
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn("Bar");
|
||||
table.AddRow("Baz", "Qux");
|
||||
table.AddRow("Corgi", "Waldo");
|
||||
|
||||
// When
|
||||
console.Render(new Padder(table).SetPadding(1, 2, 3, 4));
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(12);
|
||||
console.Lines[00].ShouldBe(" ");
|
||||
console.Lines[01].ShouldBe(" ");
|
||||
console.Lines[02].ShouldBe(" ┌───────┬───────┐ ");
|
||||
console.Lines[03].ShouldBe(" │ Foo │ Bar │ ");
|
||||
console.Lines[04].ShouldBe(" ├───────┼───────┤ ");
|
||||
console.Lines[05].ShouldBe(" │ Baz │ Qux │ ");
|
||||
console.Lines[06].ShouldBe(" │ Corgi │ Waldo │ ");
|
||||
console.Lines[07].ShouldBe(" └───────┴───────┘ ");
|
||||
console.Lines[08].ShouldBe(" ");
|
||||
console.Lines[09].ShouldBe(" ");
|
||||
console.Lines[10].ShouldBe(" ");
|
||||
console.Lines[11].ShouldBe(" ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_Expanded_Padded_Object_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 60);
|
||||
var table = new Table();
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn("Bar");
|
||||
table.AddRow("Baz", "Qux");
|
||||
table.AddRow("Corgi", "Waldo");
|
||||
|
||||
// When
|
||||
console.Render(new Padder(table)
|
||||
.SetPadding(1, 2, 3, 4)
|
||||
.Expand());
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(12);
|
||||
console.Lines[00].ShouldBe(" ");
|
||||
console.Lines[01].ShouldBe(" ");
|
||||
console.Lines[02].ShouldBe(" ┌───────┬───────┐ ");
|
||||
console.Lines[03].ShouldBe(" │ Foo │ Bar │ ");
|
||||
console.Lines[04].ShouldBe(" ├───────┼───────┤ ");
|
||||
console.Lines[05].ShouldBe(" │ Baz │ Qux │ ");
|
||||
console.Lines[06].ShouldBe(" │ Corgi │ Waldo │ ");
|
||||
console.Lines[07].ShouldBe(" └───────┴───────┘ ");
|
||||
console.Lines[08].ShouldBe(" ");
|
||||
console.Lines[09].ShouldBe(" ");
|
||||
console.Lines[10].ShouldBe(" ");
|
||||
console.Lines[11].ShouldBe(" ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_Padded_Object_Correctly_When_Nested_Within_Other_Object()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 60);
|
||||
var table = new Table();
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn("Bar", c => c.PadLeft(0).PadRight(0));
|
||||
table.AddRow("Baz", "Qux");
|
||||
table.AddRow(new Text("Corgi"), new Padder(new Panel("Waldo"))
|
||||
.SetPadding(2, 1, 2, 1));
|
||||
|
||||
// When
|
||||
console.Render(new Padder(table)
|
||||
.SetPadding(1, 2, 3, 4)
|
||||
.Expand());
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(16);
|
||||
console.Lines[00].ShouldBe(" ");
|
||||
console.Lines[01].ShouldBe(" ");
|
||||
console.Lines[02].ShouldBe(" ┌───────┬─────────────┐ ");
|
||||
console.Lines[03].ShouldBe(" │ Foo │Bar │ ");
|
||||
console.Lines[04].ShouldBe(" ├───────┼─────────────┤ ");
|
||||
console.Lines[05].ShouldBe(" │ Baz │Qux │ ");
|
||||
console.Lines[06].ShouldBe(" │ Corgi │ │ ");
|
||||
console.Lines[07].ShouldBe(" │ │ ┌───────┐ │ ");
|
||||
console.Lines[08].ShouldBe(" │ │ │ Waldo │ │ ");
|
||||
console.Lines[09].ShouldBe(" │ │ └───────┘ │ ");
|
||||
console.Lines[10].ShouldBe(" │ │ │ ");
|
||||
console.Lines[11].ShouldBe(" └───────┴─────────────┘ ");
|
||||
console.Lines[12].ShouldBe(" ");
|
||||
console.Lines[13].ShouldBe(" ");
|
||||
console.Lines[14].ShouldBe(" ");
|
||||
console.Lines[15].ShouldBe(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,25 @@ namespace Spectre.Console.Tests.Unit
|
||||
console.Lines[2].ShouldBe("└─────────────┘");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_Panel_With_Padding_Set_To_Zero()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 80);
|
||||
|
||||
// When
|
||||
console.Render(new Panel(new Text("Hello World"))
|
||||
{
|
||||
Padding = new Padding(0, 0, 0, 0),
|
||||
});
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(3);
|
||||
console.Lines[0].ShouldBe("┌───────────┐");
|
||||
console.Lines[1].ShouldBe("│Hello World│");
|
||||
console.Lines[2].ShouldBe("└───────────┘");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_Panel_With_Padding()
|
||||
{
|
||||
@@ -30,14 +49,17 @@ namespace Spectre.Console.Tests.Unit
|
||||
// When
|
||||
console.Render(new Panel(new Text("Hello World"))
|
||||
{
|
||||
Padding = new Padding(3, 5),
|
||||
Padding = new Padding(3, 1, 5, 2),
|
||||
});
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(3);
|
||||
console.Lines.Count.ShouldBe(6);
|
||||
console.Lines[0].ShouldBe("┌───────────────────┐");
|
||||
console.Lines[1].ShouldBe("│ Hello World │");
|
||||
console.Lines[2].ShouldBe("└───────────────────┘");
|
||||
console.Lines[1].ShouldBe("│ │");
|
||||
console.Lines[2].ShouldBe("│ Hello World │");
|
||||
console.Lines[3].ShouldBe("│ │");
|
||||
console.Lines[4].ShouldBe("│ │");
|
||||
console.Lines[5].ShouldBe("└───────────────────┘");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -49,9 +71,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
// When
|
||||
console.Render(new Panel("Hello World")
|
||||
{
|
||||
Header = new Header("Greeting"),
|
||||
Header = new PanelHeader("Greeting"),
|
||||
Expand = true,
|
||||
Padding = new Padding(2, 2),
|
||||
Padding = new Padding(2, 0, 2, 0),
|
||||
});
|
||||
|
||||
// Then
|
||||
@@ -70,7 +92,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
// When
|
||||
console.Render(new Panel("Hello World")
|
||||
{
|
||||
Header = new Header("Greeting").LeftAligned(),
|
||||
Header = new PanelHeader("Greeting").LeftAligned(),
|
||||
Expand = true,
|
||||
});
|
||||
|
||||
@@ -90,7 +112,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
// When
|
||||
console.Render(new Panel("Hello World")
|
||||
{
|
||||
Header = new Header("Greeting").Centered(),
|
||||
Header = new PanelHeader("Greeting").Centered(),
|
||||
Expand = true,
|
||||
});
|
||||
|
||||
@@ -110,7 +132,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
// When
|
||||
console.Render(new Panel("Hello World")
|
||||
{
|
||||
Header = new Header("Greeting").RightAligned(),
|
||||
Header = new PanelHeader("Greeting").RightAligned(),
|
||||
Expand = true,
|
||||
});
|
||||
|
||||
@@ -130,7 +152,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
// When
|
||||
console.Render(new Panel("Hello World")
|
||||
{
|
||||
Header = new Header("Greeting"),
|
||||
Header = new PanelHeader("Greeting"),
|
||||
Expand = true,
|
||||
});
|
||||
|
||||
|
||||
66
src/Spectre.Console.Tests/Unit/RecorderTests.cs
Normal file
66
src/Spectre.Console.Tests/Unit/RecorderTests.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
public sealed class RecorderTests
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Export_Text_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var recorder = new Recorder(console);
|
||||
|
||||
recorder.Render(new Table()
|
||||
.AddColumns("Foo", "Bar", "Qux")
|
||||
.AddRow("Corgi", "Waldo", "Zap")
|
||||
.AddRow(new Panel("Hello World").RoundedBorder()));
|
||||
|
||||
// When
|
||||
var result = recorder.ExportText().Split(new[] { '\n' });
|
||||
|
||||
// Then
|
||||
result.Length.ShouldBe(8);
|
||||
result[0].ShouldBe("┌─────────────────┬───────┬─────┐");
|
||||
result[1].ShouldBe("│ Foo │ Bar │ Qux │");
|
||||
result[2].ShouldBe("├─────────────────┼───────┼─────┤");
|
||||
result[3].ShouldBe("│ Corgi │ Waldo │ Zap │");
|
||||
result[4].ShouldBe("│ ╭─────────────╮ │ │ │");
|
||||
result[5].ShouldBe("│ │ Hello World │ │ │ │");
|
||||
result[6].ShouldBe("│ ╰─────────────╯ │ │ │");
|
||||
result[7].ShouldBe("└─────────────────┴───────┴─────┘");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Export_Html_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole();
|
||||
var recorder = new Recorder(console);
|
||||
|
||||
recorder.Render(new Table()
|
||||
.AddColumns("[red on black]Foo[/]", "[green bold]Bar[/]", "[blue italic]Qux[/]")
|
||||
.AddRow("[invert underline]Corgi[/]", "[bold strikethrough]Waldo[/]", "[dim]Zap[/]")
|
||||
.AddRow(new Panel("[blue]Hello World[/]")
|
||||
.SetBorderColor(Color.Red).RoundedBorder()));
|
||||
|
||||
// When
|
||||
var html = recorder.ExportHtml();
|
||||
var result = html.Split(new[] { '\n' });
|
||||
|
||||
// Then
|
||||
result.Length.ShouldBe(10);
|
||||
result[0].ShouldBe("<pre style=\"font-size:90%;font-family:consolas,'Courier New',monospace\">");
|
||||
result[1].ShouldBe("<span>┌─────────────────┬───────┬─────┐</span>");
|
||||
result[2].ShouldBe("<span>│ </span><span style=\"color: #FF0000;background-color: #000000\">Foo</span><span> │ </span><span style=\"color: #008000;font-weight: bold;font-style: italic\">Bar</span><span> │ </span><span style=\"color: #0000FF\">Qux</span><span> │</span>");
|
||||
result[3].ShouldBe("<span>├─────────────────┼───────┼─────┤</span>");
|
||||
result[4].ShouldBe("<span>│ </span><span style=\"text-decoration: underline\">Corgi</span><span> │ </span><span style=\"font-weight: bold;font-style: italic;text-decoration: line-through\">Waldo</span><span> │ </span><span style=\"color: #7F7F7F\">Zap</span><span> │</span>");
|
||||
result[5].ShouldBe("<span>│ </span><span style=\"color: #FF0000\">╭─────────────╮</span><span> │ │ │</span>");
|
||||
result[6].ShouldBe("<span>│ </span><span style=\"color: #FF0000\">│</span><span> </span><span style=\"color: #0000FF\">Hello World</span><span> </span><span style=\"color: #FF0000\">│</span><span> │ │ │</span>");
|
||||
result[7].ShouldBe("<span>│ </span><span style=\"color: #FF0000\">╰─────────────╯</span><span> │ │ │</span>");
|
||||
result[8].ShouldBe("<span>└─────────────────┴───────┴─────┘</span>");
|
||||
result[9].ShouldBe("</pre>");
|
||||
}
|
||||
}
|
||||
}
|
||||
96
src/Spectre.Console.Tests/Unit/RowsTests.cs
Normal file
96
src/Spectre.Console.Tests/Unit/RowsTests.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using Shouldly;
|
||||
using Spectre.Console.Rendering;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
public sealed class RowsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Render_Rows()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 60);
|
||||
var rows = new Rows(
|
||||
new IRenderable[]
|
||||
{
|
||||
new Markup("Hello"),
|
||||
new Table()
|
||||
.AddColumns("Foo", "Bar")
|
||||
.AddRow("Baz", "Qux"),
|
||||
new Markup("World"),
|
||||
});
|
||||
|
||||
// When
|
||||
console.Render(rows);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(7);
|
||||
console.Lines[0].ShouldBe("Hello");
|
||||
console.Lines[1].ShouldBe("┌─────┬─────┐");
|
||||
console.Lines[2].ShouldBe("│ Foo │ Bar │");
|
||||
console.Lines[3].ShouldBe("├─────┼─────┤");
|
||||
console.Lines[4].ShouldBe("│ Baz │ Qux │");
|
||||
console.Lines[5].ShouldBe("└─────┴─────┘");
|
||||
console.Lines[6].ShouldBe("World");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_Rows_Correctly_Inside_Other_Widget()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 60);
|
||||
var table = new Table()
|
||||
.AddColumns("Foo", "Bar")
|
||||
.AddRow("HELLO WORLD")
|
||||
.AddRow(
|
||||
new Rows(new IRenderable[]
|
||||
{
|
||||
new Markup("Hello"),
|
||||
new Markup("World"),
|
||||
}), new Text("Qux"));
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(7);
|
||||
console.Lines[0].ShouldBe("┌─────────────┬─────┐");
|
||||
console.Lines[1].ShouldBe("│ Foo │ Bar │");
|
||||
console.Lines[2].ShouldBe("├─────────────┼─────┤");
|
||||
console.Lines[3].ShouldBe("│ HELLO WORLD │ │");
|
||||
console.Lines[4].ShouldBe("│ Hello │ Qux │");
|
||||
console.Lines[5].ShouldBe("│ World │ │");
|
||||
console.Lines[6].ShouldBe("└─────────────┴─────┘");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Render_Rows_Correctly_Inside_Other_Widget_When_Expanded()
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 60);
|
||||
var table = new Table()
|
||||
.AddColumns("Foo", "Bar")
|
||||
.AddRow("HELLO WORLD")
|
||||
.AddRow(
|
||||
new Rows(new IRenderable[]
|
||||
{
|
||||
new Markup("Hello"),
|
||||
new Markup("World"),
|
||||
}).Expand(), new Text("Qux"));
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
// Then
|
||||
console.Lines.Count.ShouldBe(7);
|
||||
console.Lines[0].ShouldBe("┌────────────────────────────────────────────────────┬─────┐");
|
||||
console.Lines[1].ShouldBe("│ Foo │ Bar │");
|
||||
console.Lines[2].ShouldBe("├────────────────────────────────────────────────────┼─────┤");
|
||||
console.Lines[3].ShouldBe("│ HELLO WORLD │ │");
|
||||
console.Lines[4].ShouldBe("│ Hello │ Qux │");
|
||||
console.Lines[5].ShouldBe("│ World │ │");
|
||||
console.Lines[6].ShouldBe("└────────────────────────────────────────────────────┴─────┘");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
// Given
|
||||
var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic);
|
||||
var other = new Style(Color.Green, Color.Silver, Decoration.Underline);
|
||||
var other = new Style(Color.Green, Color.Silver, Decoration.Underline, "https://example.com");
|
||||
|
||||
// When
|
||||
var result = first.Combine(other);
|
||||
@@ -20,6 +20,77 @@ namespace Spectre.Console.Tests.Unit
|
||||
result.Foreground.ShouldBe(Color.Green);
|
||||
result.Background.ShouldBe(Color.Silver);
|
||||
result.Decoration.ShouldBe(Decoration.Bold | Decoration.Italic | Decoration.Underline);
|
||||
result.Link.ShouldBe("https://example.com");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Consider_Two_Identical_Styles_Equal()
|
||||
{
|
||||
// Given
|
||||
var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com");
|
||||
var second = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com");
|
||||
|
||||
// When
|
||||
var result = first.Equals(second);
|
||||
|
||||
// Then
|
||||
result.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Consider_Two_Styles_With_Different_Foreground_Colors_Equal()
|
||||
{
|
||||
// Given
|
||||
var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com");
|
||||
var second = new Style(Color.Blue, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com");
|
||||
|
||||
// When
|
||||
var result = first.Equals(second);
|
||||
|
||||
// Then
|
||||
result.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Consider_Two_Styles_With_Different_Background_Colors_Equal()
|
||||
{
|
||||
// Given
|
||||
var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com");
|
||||
var second = new Style(Color.White, Color.Blue, Decoration.Bold | Decoration.Italic, "http://example.com");
|
||||
|
||||
// When
|
||||
var result = first.Equals(second);
|
||||
|
||||
// Then
|
||||
result.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Consider_Two_Styles_With_Different_Decorations_Equal()
|
||||
{
|
||||
// Given
|
||||
var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com");
|
||||
var second = new Style(Color.White, Color.Yellow, Decoration.Bold, "http://example.com");
|
||||
|
||||
// When
|
||||
var result = first.Equals(second);
|
||||
|
||||
// Then
|
||||
result.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Consider_Two_Styles_With_Different_Links_Equal()
|
||||
{
|
||||
// Given
|
||||
var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com");
|
||||
var second = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://foo.com");
|
||||
|
||||
// When
|
||||
var result = first.Equals(second);
|
||||
|
||||
// Then
|
||||
result.ShouldBeFalse();
|
||||
}
|
||||
|
||||
public sealed class TheParseMethod
|
||||
@@ -62,16 +133,36 @@ namespace Spectre.Console.Tests.Unit
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Parse_Text_And_Decoration()
|
||||
public void Should_Parse_Link_Without_Address()
|
||||
{
|
||||
// Given, When
|
||||
var result = Style.Parse("bold underline blue on green");
|
||||
var result = Style.Parse("link");
|
||||
|
||||
// Then
|
||||
result.ShouldNotBeNull();
|
||||
result.Decoration.ShouldBe(Decoration.Bold | Decoration.Underline);
|
||||
result.Foreground.ShouldBe(Color.Blue);
|
||||
result.Background.ShouldBe(Color.Green);
|
||||
result.Link.ShouldBe("https://emptylink");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Parse_Link()
|
||||
{
|
||||
// Given, When
|
||||
var result = Style.Parse("link=https://example.com");
|
||||
|
||||
// Then
|
||||
result.ShouldNotBeNull();
|
||||
result.Link.ShouldBe("https://example.com");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Link_Is_Set_Twice()
|
||||
{
|
||||
// Given, When
|
||||
var result = Record.Exception(() => Style.Parse("link=https://example.com link=https://example.com"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<InvalidOperationException>();
|
||||
result.Message.ShouldBe("A link has already been set.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -131,6 +222,20 @@ namespace Spectre.Console.Tests.Unit
|
||||
result.Message.ShouldBe("Could not find color 'lol'.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Parse_Colors_And_Decoration_And_Link()
|
||||
{
|
||||
// Given, When
|
||||
var result = Style.Parse("link=https://example.com bold underline blue on green");
|
||||
|
||||
// Then
|
||||
result.ShouldNotBeNull();
|
||||
result.Decoration.ShouldBe(Decoration.Bold | Decoration.Underline);
|
||||
result.Foreground.ShouldBe(Color.Blue);
|
||||
result.Background.ShouldBe(Color.Green);
|
||||
result.Link.ShouldBe("https://example.com");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("#FF0000 on #0000FF")]
|
||||
[InlineData("#F00 on #00F")]
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
// A simple table
|
||||
var console = new PlainConsole(width: 80);
|
||||
var table = new Table() { BorderKind = BorderKind.Rounded };
|
||||
var table = new Table() { Border = Border.Rounded };
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn("Bar");
|
||||
table.AddColumn(new TableColumn("Baz") { Alignment = Justify.Right });
|
||||
@@ -183,7 +183,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
// Render a table in some panels.
|
||||
console.Render(new Panel(new Panel(table)
|
||||
{
|
||||
BorderKind = BorderKind.Ascii,
|
||||
Border = Border.Ascii,
|
||||
}));
|
||||
|
||||
// Then
|
||||
@@ -255,7 +255,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 80);
|
||||
var table = new Table { BorderKind = BorderKind.Ascii };
|
||||
var table = new Table { Border = Border.Ascii };
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
@@ -278,7 +278,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 80);
|
||||
var table = new Table { BorderKind = BorderKind.Rounded };
|
||||
var table = new Table { Border = Border.Rounded };
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
@@ -301,7 +301,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
// Given
|
||||
var console = new PlainConsole(width: 80);
|
||||
var table = new Table { BorderKind = BorderKind.None };
|
||||
var table = new Table { Border = Border.None };
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
@@ -347,7 +347,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
var console = new PlainConsole(width: 80);
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar");
|
||||
table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 2) });
|
||||
table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) });
|
||||
table.AddRow("Qux\nQuuux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
|
||||
@@ -372,7 +372,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
var console = new PlainConsole(width: 80);
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar");
|
||||
table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 2) });
|
||||
table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) });
|
||||
|
||||
// When
|
||||
console.Render(table);
|
||||
|
||||
@@ -37,14 +37,14 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Render_Unstyled_Text_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole(width: 80);
|
||||
var console = new PlainConsole(width: 80);
|
||||
var text = new Text("Hello World");
|
||||
|
||||
// When
|
||||
fixture.Render(text);
|
||||
console.Render(text);
|
||||
|
||||
// Then
|
||||
fixture.Output
|
||||
console.Output
|
||||
.NormalizeLineEndings()
|
||||
.ShouldBe("Hello World");
|
||||
}
|
||||
@@ -55,14 +55,14 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Write_Line_Breaks(string input)
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole(width: 5);
|
||||
var console = new PlainConsole(width: 5);
|
||||
var text = new Text(input);
|
||||
|
||||
// When
|
||||
fixture.Render(text);
|
||||
console.Render(text);
|
||||
|
||||
// Then
|
||||
fixture.RawOutput.ShouldBe("Hello\n\nWorld\n\n");
|
||||
console.RawOutput.ShouldBe("Hello\n\nWorld\n\n");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -87,14 +87,14 @@ namespace Spectre.Console.Tests.Unit
|
||||
int width, string input, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole(width);
|
||||
var console = new PlainConsole(width);
|
||||
var text = new Text(input);
|
||||
|
||||
// When
|
||||
fixture.Render(text);
|
||||
console.Render(text);
|
||||
|
||||
// Then
|
||||
fixture.Output
|
||||
console.Output
|
||||
.NormalizeLineEndings()
|
||||
.ShouldBe(expected);
|
||||
}
|
||||
@@ -106,15 +106,15 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Overflow_Text_Correctly(Overflow overflow, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole(14);
|
||||
var console = new PlainConsole(14);
|
||||
var text = new Text("foo pneumonoultramicroscopicsilicovolcanoconiosis bar qux")
|
||||
.SetOverflow(overflow);
|
||||
|
||||
// When
|
||||
fixture.Render(text);
|
||||
console.Render(text);
|
||||
|
||||
// Then
|
||||
fixture.Output
|
||||
console.Output
|
||||
.NormalizeLineEndings()
|
||||
.ShouldBe(expected);
|
||||
}
|
||||
|
||||
@@ -25,10 +25,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grid", "..\examples\Grid\Gr
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Colors", "..\examples\Colors\Colors.csproj", "{1F51C55C-BA4C-4856-9001-0F7924FFB179}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Diagnostic", "..\examples\Diagnostic\Diagnostic.csproj", "{4337F255-88E9-4408-81A3-DF1AF58AC753}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Columns", "..\examples\Columns\Columns.csproj", "{33357599-C79D-4299-888F-634E2C3EACEF}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Info", "..\examples\Info\Info.csproj", "{225CE0D4-06AB-411A-8D29-707504FE53B3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Borders", "..\examples\Borders\Borders.csproj", "{094245E6-4C94-485D-B5AC-3153E878B112}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Links", "..\examples\Links\Links.csproj", "{6AF8C93B-AA41-4F44-8B1B-B8D166576174}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emojis", "..\examples\Emojis\Emojis.csproj", "{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -111,18 +117,6 @@ Global
|
||||
{1F51C55C-BA4C-4856-9001-0F7924FFB179}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1F51C55C-BA4C-4856-9001-0F7924FFB179}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1F51C55C-BA4C-4856-9001-0F7924FFB179}.Release|x86.Build.0 = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|x64.Build.0 = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|x86.Build.0 = Release|Any CPU
|
||||
{33357599-C79D-4299-888F-634E2C3EACEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{33357599-C79D-4299-888F-634E2C3EACEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{33357599-C79D-4299-888F-634E2C3EACEF}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
@@ -135,6 +129,54 @@ Global
|
||||
{33357599-C79D-4299-888F-634E2C3EACEF}.Release|x64.Build.0 = Release|Any CPU
|
||||
{33357599-C79D-4299-888F-634E2C3EACEF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{33357599-C79D-4299-888F-634E2C3EACEF}.Release|x86.Build.0 = Release|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Release|x64.Build.0 = Release|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3}.Release|x86.Build.0 = Release|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Release|x64.Build.0 = Release|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112}.Release|x86.Build.0 = Release|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Release|x64.Build.0 = Release|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174}.Release|x86.Build.0 = Release|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -144,8 +186,11 @@ Global
|
||||
{BFF37228-B376-4ADD-9657-4E501F929713} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{C7FF6FDB-FB59-4517-8669-521C96AB7323} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{1F51C55C-BA4C-4856-9001-0F7924FFB179} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{33357599-C79D-4299-888F-634E2C3EACEF} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{225CE0D4-06AB-411A-8D29-707504FE53B3} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{094245E6-4C94-485D-B5AC-3153E878B112} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{6AF8C93B-AA41-4F44-8B1B-B8D166576174} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{1EABB956-957F-4C1A-8AC0-FD19C8F3C2F2} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5729B071-67A0-48FB-8B1B-275E6822086C}
|
||||
|
||||
67
src/Spectre.Console/AnsiConsole.Recording.cs
Normal file
67
src/Spectre.Console/AnsiConsole.Recording.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
/// <summary>
|
||||
/// A console capable of writing ANSI escape sequences.
|
||||
/// </summary>
|
||||
public static partial class AnsiConsole
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts recording the console output.
|
||||
/// </summary>
|
||||
public static void Record()
|
||||
{
|
||||
_recorder = new Recorder(_console.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports all recorded console output as text.
|
||||
/// </summary>
|
||||
/// <returns>The recorded output as text.</returns>
|
||||
public static string ExportText()
|
||||
{
|
||||
if (_recorder == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot export text since a recording hasn't been started.");
|
||||
}
|
||||
|
||||
return _recorder.ExportText();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports all recorded console output as HTML.
|
||||
/// </summary>
|
||||
/// <returns>The recorded output as HTML.</returns>
|
||||
public static string ExportHtml()
|
||||
{
|
||||
if (_recorder == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot export HTML since a recording hasn't been started.");
|
||||
}
|
||||
|
||||
return _recorder.ExportHtml();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports all recorded console output using a custom encoder.
|
||||
/// </summary>
|
||||
/// <param name="encoder">The encoder to use.</param>
|
||||
/// <returns>The recorded output.</returns>
|
||||
public static string ExportCustom(IAnsiConsoleEncoder encoder)
|
||||
{
|
||||
if (_recorder == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot export HTML since a recording hasn't been started.");
|
||||
}
|
||||
|
||||
if (encoder is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(encoder));
|
||||
}
|
||||
|
||||
return _recorder.Export(encoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
85
src/Spectre.Console/AnsiConsole.State.cs
Normal file
85
src/Spectre.Console/AnsiConsole.State.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Spectre.Console.Internal;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
/// <summary>
|
||||
/// A console capable of writing ANSI escape sequences.
|
||||
/// </summary>
|
||||
public static partial class AnsiConsole
|
||||
{
|
||||
private static ConsoleColor _defaultForeground;
|
||||
private static ConsoleColor _defaultBackground;
|
||||
|
||||
internal static Style CurrentStyle { get; private set; } = Style.Plain;
|
||||
internal static bool Created { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the foreground color.
|
||||
/// </summary>
|
||||
public static Color Foreground
|
||||
{
|
||||
get => CurrentStyle.Foreground;
|
||||
set => CurrentStyle = CurrentStyle.WithForeground(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the background color.
|
||||
/// </summary>
|
||||
public static Color Background
|
||||
{
|
||||
get => CurrentStyle.Background;
|
||||
set => CurrentStyle = CurrentStyle.WithBackground(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the text decoration.
|
||||
/// </summary>
|
||||
public static Decoration Decoration
|
||||
{
|
||||
get => CurrentStyle.Decoration;
|
||||
set => CurrentStyle = CurrentStyle.WithDecoration(value);
|
||||
}
|
||||
|
||||
internal static void Initialize(TextWriter? @out)
|
||||
{
|
||||
if (@out?.IsStandardOut() ?? false)
|
||||
{
|
||||
Foreground = _defaultForeground = System.Console.ForegroundColor;
|
||||
Background = _defaultBackground = System.Console.BackgroundColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
Foreground = _defaultForeground = Color.Silver;
|
||||
Background = _defaultBackground = Color.Black;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets colors and text decorations.
|
||||
/// </summary>
|
||||
public static void Reset()
|
||||
{
|
||||
ResetColors();
|
||||
ResetDecoration();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the current applied text decorations.
|
||||
/// </summary>
|
||||
public static void ResetDecoration()
|
||||
{
|
||||
Decoration = Decoration.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the current applied foreground and background colors.
|
||||
/// </summary>
|
||||
public static void ResetColors()
|
||||
{
|
||||
Foreground = _defaultForeground;
|
||||
Background = _defaultBackground;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(string value)
|
||||
{
|
||||
Console.Write(value);
|
||||
Console.Write(value, CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -24,7 +24,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(int value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -35,7 +35,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, int value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,7 +45,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(uint value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,7 +56,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, uint value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -66,7 +66,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(long value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,7 +77,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, long value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,7 +87,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(ulong value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -98,7 +98,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, ulong value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,7 +108,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(float value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -119,7 +119,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, float value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,7 +129,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(double value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -140,7 +140,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, double value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -149,7 +149,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(decimal value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -159,7 +159,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, decimal value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,7 +168,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(bool value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -178,7 +178,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, bool value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -187,7 +187,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(char value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -197,7 +197,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, char value)
|
||||
{
|
||||
Console.Write(value.ToString(provider));
|
||||
Console.Write(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -206,7 +206,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(char[] value)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, value);
|
||||
Write(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -216,7 +216,15 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void Write(IFormatProvider provider, char[] value)
|
||||
{
|
||||
Console.Write(provider, value);
|
||||
if (value is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
for (var index = 0; index < value.Length; index++)
|
||||
{
|
||||
Console.Write(value[index].ToString(provider), CurrentStyle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -227,7 +235,7 @@ namespace Spectre.Console
|
||||
/// <param name="args">An array of objects to write.</param>
|
||||
public static void Write(string format, params object[] args)
|
||||
{
|
||||
Console.Write(CultureInfo.CurrentCulture, format, args);
|
||||
Write(CultureInfo.CurrentCulture, format, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -239,7 +247,7 @@ namespace Spectre.Console
|
||||
/// <param name="args">An array of objects to write.</param>
|
||||
public static void Write(IFormatProvider provider, string format, params object[] args)
|
||||
{
|
||||
Console.Write(string.Format(provider, format, args));
|
||||
Console.Write(string.Format(provider, format, args), CurrentStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(string value)
|
||||
{
|
||||
Console.WriteLine(value);
|
||||
Console.WriteLine(value, CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,7 +32,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(int value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,7 +43,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, int value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,7 +53,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(uint value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,7 +64,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, uint value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,7 +74,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(long value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,7 +85,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, long value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,7 +95,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(ulong value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,7 +106,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, ulong value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -116,7 +116,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(float value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -127,7 +127,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, float value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -137,7 +137,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(double value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -148,7 +148,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, double value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -158,7 +158,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(decimal value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -169,7 +169,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, decimal value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -179,7 +179,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(bool value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -190,7 +190,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, bool value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -200,7 +200,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(char value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -211,7 +211,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, char value)
|
||||
{
|
||||
Console.WriteLine(value.ToString(provider));
|
||||
Console.WriteLine(value.ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -221,7 +221,7 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(char[] value)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, value);
|
||||
WriteLine(CultureInfo.CurrentCulture, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -232,7 +232,17 @@ namespace Spectre.Console
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, char[] value)
|
||||
{
|
||||
Console.WriteLine(provider, value);
|
||||
if (value is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
for (var index = 0; index < value.Length; index++)
|
||||
{
|
||||
Console.Write(value[index].ToString(provider), CurrentStyle);
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -244,7 +254,7 @@ namespace Spectre.Console
|
||||
/// <param name="args">An array of objects to write.</param>
|
||||
public static void WriteLine(string format, params object[] args)
|
||||
{
|
||||
Console.WriteLine(CultureInfo.CurrentCulture, format, args);
|
||||
WriteLine(CultureInfo.CurrentCulture, format, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -257,7 +267,7 @@ namespace Spectre.Console
|
||||
/// <param name="args">An array of objects to write.</param>
|
||||
public static void WriteLine(IFormatProvider provider, string format, params object[] args)
|
||||
{
|
||||
Console.WriteLine(string.Format(provider, format, args));
|
||||
Console.WriteLine(string.Format(provider, format, args), CurrentStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,22 +16,23 @@ namespace Spectre.Console
|
||||
ColorSystem = ColorSystemSupport.Detect,
|
||||
Out = System.Console.Out,
|
||||
});
|
||||
Initialize(System.Console.Out);
|
||||
Created = true;
|
||||
return console;
|
||||
});
|
||||
|
||||
private static Recorder? _recorder;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current renderer.
|
||||
/// Gets the underlying <see cref="IAnsiConsole"/>.
|
||||
/// </summary>
|
||||
public static IAnsiConsole Console => _console.Value;
|
||||
public static IAnsiConsole Console => _recorder ?? _console.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the console's capabilities.
|
||||
/// </summary>
|
||||
public static Capabilities Capabilities => Console.Capabilities;
|
||||
|
||||
internal static bool Created { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the buffer width of the console.
|
||||
/// </summary>
|
||||
@@ -48,33 +49,6 @@ namespace Spectre.Console
|
||||
get => Console.Height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the foreground color.
|
||||
/// </summary>
|
||||
public static Color Foreground
|
||||
{
|
||||
get => Console.Foreground;
|
||||
set => Console.SetColor(value, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the background color.
|
||||
/// </summary>
|
||||
public static Color Background
|
||||
{
|
||||
get => Console.Background;
|
||||
set => Console.SetColor(value, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the text decoration.
|
||||
/// </summary>
|
||||
public static Decoration Decoration
|
||||
{
|
||||
get => Console.Decoration;
|
||||
set => Console.Decoration = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="IAnsiConsole"/> instance
|
||||
/// from the provided settings.
|
||||
@@ -83,31 +57,7 @@ namespace Spectre.Console
|
||||
/// <returns>An <see cref="IAnsiConsole"/> instance.</returns>
|
||||
public static IAnsiConsole Create(AnsiConsoleSettings settings)
|
||||
{
|
||||
return ConsoleBuilder.Build(settings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets colors and text decorations.
|
||||
/// </summary>
|
||||
public static void Reset()
|
||||
{
|
||||
Console.Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the current applied text decorations.
|
||||
/// </summary>
|
||||
public static void ResetDecoration()
|
||||
{
|
||||
Console.ResetDecoration();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the current applied foreground and background colors.
|
||||
/// </summary>
|
||||
public static void ResetColors()
|
||||
{
|
||||
Console.ResetColors();
|
||||
return AnsiConsoleBuilder.Build(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
public ColorSystemSupport ColorSystem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the link identity generator.
|
||||
/// </summary>
|
||||
public ILinkIdentityGenerator? LinkIdentityGenerator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the out buffer.
|
||||
/// </summary>
|
||||
|
||||
97
src/Spectre.Console/Border.Known.cs
Normal file
97
src/Spectre.Console/Border.Known.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a border.
|
||||
/// </summary>
|
||||
public abstract partial class Border
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an invisible border.
|
||||
/// </summary>
|
||||
public static Border None { get; } = new NoBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets an ASCII border.
|
||||
/// </summary>
|
||||
public static Border Ascii { get; } = new AsciiBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets another ASCII border.
|
||||
/// </summary>
|
||||
public static Border Ascii2 { get; } = new Ascii2Border();
|
||||
|
||||
/// <summary>
|
||||
/// Gets an ASCII border with a double header border.
|
||||
/// </summary>
|
||||
public static Border AsciiDoubleHead { get; } = new AsciiDoubleHeadBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a square border.
|
||||
/// </summary>
|
||||
public static Border Square { get; } = new SquareBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a rounded border.
|
||||
/// </summary>
|
||||
public static Border Rounded { get; } = new RoundedBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a minimal border.
|
||||
/// </summary>
|
||||
public static Border Minimal { get; } = new MinimalBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a minimal border with a heavy head.
|
||||
/// </summary>
|
||||
public static Border MinimalHeavyHead { get; } = new MinimalHeavyHeadBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a minimal border with a double header border.
|
||||
/// </summary>
|
||||
public static Border MinimalDoubleHead { get; } = new MinimalDoubleHeadBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a simple border.
|
||||
/// </summary>
|
||||
public static Border Simple { get; } = new SimpleBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a simple border with heavy lines.
|
||||
/// </summary>
|
||||
public static Border SimpleHeavy { get; } = new SimpleHeavyBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a horizontal border.
|
||||
/// </summary>
|
||||
public static Border Horizontal { get; } = new HorizontalBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a heavy border.
|
||||
/// </summary>
|
||||
public static Border Heavy { get; } = new HeavyBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a border with a heavy edge.
|
||||
/// </summary>
|
||||
public static Border HeavyEdge { get; } = new HeavyEdgeBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a border with a heavy header.
|
||||
/// </summary>
|
||||
public static Border HeavyHead { get; } = new HeavyHeadBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a double border.
|
||||
/// </summary>
|
||||
[SuppressMessage("Naming", "CA1720:Identifier contains type name")]
|
||||
public static Border Double { get; } = new DoubleBorder();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a border with a double edge.
|
||||
/// </summary>
|
||||
public static Border DoubleEdge { get; } = new DoubleEdgeBorder();
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,26 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
namespace Spectre.Console
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a border used by tables.
|
||||
/// Represents a border.
|
||||
/// </summary>
|
||||
public abstract class Border
|
||||
public abstract partial class Border
|
||||
{
|
||||
private readonly Dictionary<BorderPart, string> _lookup;
|
||||
|
||||
private static readonly Dictionary<BorderKind, Border> _borders = new Dictionary<BorderKind, Border>
|
||||
{
|
||||
{ BorderKind.None, new NoBorder() },
|
||||
{ BorderKind.Ascii, new AsciiBorder() },
|
||||
{ BorderKind.Square, new SquareBorder() },
|
||||
{ BorderKind.Rounded, new RoundedBorder() },
|
||||
};
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not the border is visible.
|
||||
/// </summary>
|
||||
public virtual bool Visible { get; } = true;
|
||||
|
||||
private static readonly Dictionary<BorderKind, BorderKind> _safeLookup = new Dictionary<BorderKind, BorderKind>
|
||||
{
|
||||
{ BorderKind.Rounded, BorderKind.Square },
|
||||
};
|
||||
/// <summary>
|
||||
/// Gets the safe border for this border or <c>null</c> if none exist.
|
||||
/// </summary>
|
||||
public virtual Border? SafeBorder { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Border"/> class.
|
||||
@@ -33,27 +31,6 @@ namespace Spectre.Console.Rendering
|
||||
_lookup = Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Border"/> represented by the specified <see cref="BorderKind"/>.
|
||||
/// </summary>
|
||||
/// <param name="kind">The kind of border to get.</param>
|
||||
/// <param name="safe">Whether or not to get a "safe" border that can be rendered in a legacy console.</param>
|
||||
/// <returns>A <see cref="Border"/> instance representing the specified <see cref="BorderKind"/>.</returns>
|
||||
public static Border GetBorder(BorderKind kind, bool safe)
|
||||
{
|
||||
if (safe && _safeLookup.TryGetValue(kind, out var safeKind))
|
||||
{
|
||||
kind = safeKind;
|
||||
}
|
||||
|
||||
if (!_borders.TryGetValue(kind, out var border))
|
||||
{
|
||||
throw new InvalidOperationException("Unknown border kind");
|
||||
}
|
||||
|
||||
return border;
|
||||
}
|
||||
|
||||
private Dictionary<BorderPart, string> Initialize()
|
||||
{
|
||||
var lookup = new Dictionary<BorderPart, string>();
|
||||
37
src/Spectre.Console/Borders/Ascii2Border.cs
Normal file
37
src/Spectre.Console/Borders/Ascii2Border.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents another old school ASCII border.
|
||||
/// </summary>
|
||||
public sealed class Ascii2Border : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => "+",
|
||||
BorderPart.HeaderTop => "-",
|
||||
BorderPart.HeaderTopSeparator => "+",
|
||||
BorderPart.HeaderTopRight => "+",
|
||||
BorderPart.HeaderLeft => "|",
|
||||
BorderPart.HeaderSeparator => "|",
|
||||
BorderPart.HeaderRight => "|",
|
||||
BorderPart.HeaderBottomLeft => "|",
|
||||
BorderPart.HeaderBottom => "-",
|
||||
BorderPart.HeaderBottomSeparator => "+",
|
||||
BorderPart.HeaderBottomRight => "|",
|
||||
BorderPart.CellLeft => "|",
|
||||
BorderPart.CellSeparator => "|",
|
||||
BorderPart.CellRight => "|",
|
||||
BorderPart.FooterBottomLeft => "+",
|
||||
BorderPart.FooterBottom => "-",
|
||||
BorderPart.FooterBottomSeparator => "+",
|
||||
BorderPart.FooterBottomRight => "+",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spectre.Console/Borders/AsciiDoubleHeadBorder.cs
Normal file
37
src/Spectre.Console/Borders/AsciiDoubleHeadBorder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an old school ASCII border with a double header border.
|
||||
/// </summary>
|
||||
public sealed class AsciiDoubleHeadBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => "+",
|
||||
BorderPart.HeaderTop => "-",
|
||||
BorderPart.HeaderTopSeparator => "+",
|
||||
BorderPart.HeaderTopRight => "+",
|
||||
BorderPart.HeaderLeft => "|",
|
||||
BorderPart.HeaderSeparator => "|",
|
||||
BorderPart.HeaderRight => "|",
|
||||
BorderPart.HeaderBottomLeft => "|",
|
||||
BorderPart.HeaderBottom => "=",
|
||||
BorderPart.HeaderBottomSeparator => "+",
|
||||
BorderPart.HeaderBottomRight => "|",
|
||||
BorderPart.CellLeft => "|",
|
||||
BorderPart.CellSeparator => "|",
|
||||
BorderPart.CellRight => "|",
|
||||
BorderPart.FooterBottomLeft => "+",
|
||||
BorderPart.FooterBottom => "-",
|
||||
BorderPart.FooterBottomSeparator => "+",
|
||||
BorderPart.FooterBottomRight => "+",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spectre.Console/Borders/DoubleBorder.cs
Normal file
37
src/Spectre.Console/Borders/DoubleBorder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a double border.
|
||||
/// </summary>
|
||||
public sealed class DoubleBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => "╔",
|
||||
BorderPart.HeaderTop => "═",
|
||||
BorderPart.HeaderTopSeparator => "╦",
|
||||
BorderPart.HeaderTopRight => "╗",
|
||||
BorderPart.HeaderLeft => "║",
|
||||
BorderPart.HeaderSeparator => "║",
|
||||
BorderPart.HeaderRight => "║",
|
||||
BorderPart.HeaderBottomLeft => "╠",
|
||||
BorderPart.HeaderBottom => "═",
|
||||
BorderPart.HeaderBottomSeparator => "╬",
|
||||
BorderPart.HeaderBottomRight => "╣",
|
||||
BorderPart.CellLeft => "║",
|
||||
BorderPart.CellSeparator => "║",
|
||||
BorderPart.CellRight => "║",
|
||||
BorderPart.FooterBottomLeft => "╚",
|
||||
BorderPart.FooterBottom => "═",
|
||||
BorderPart.FooterBottomSeparator => "╩",
|
||||
BorderPart.FooterBottomRight => "╝",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spectre.Console/Borders/DoubleEdgeBorder.cs
Normal file
37
src/Spectre.Console/Borders/DoubleEdgeBorder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a border with a double edge.
|
||||
/// </summary>
|
||||
public sealed class DoubleEdgeBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => "╔",
|
||||
BorderPart.HeaderTop => "═",
|
||||
BorderPart.HeaderTopSeparator => "╤",
|
||||
BorderPart.HeaderTopRight => "╗",
|
||||
BorderPart.HeaderLeft => "║",
|
||||
BorderPart.HeaderSeparator => "│",
|
||||
BorderPart.HeaderRight => "║",
|
||||
BorderPart.HeaderBottomLeft => "╟",
|
||||
BorderPart.HeaderBottom => "─",
|
||||
BorderPart.HeaderBottomSeparator => "┼",
|
||||
BorderPart.HeaderBottomRight => "╢",
|
||||
BorderPart.CellLeft => "║",
|
||||
BorderPart.CellSeparator => "│",
|
||||
BorderPart.CellRight => "║",
|
||||
BorderPart.FooterBottomLeft => "╚",
|
||||
BorderPart.FooterBottom => "═",
|
||||
BorderPart.FooterBottomSeparator => "╧",
|
||||
BorderPart.FooterBottomRight => "╝",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/Spectre.Console/Borders/HeavyBorder.cs
Normal file
40
src/Spectre.Console/Borders/HeavyBorder.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a heavy border.
|
||||
/// </summary>
|
||||
public sealed class HeavyBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override Border? SafeBorder => Border.Square;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => "┏",
|
||||
BorderPart.HeaderTop => "━",
|
||||
BorderPart.HeaderTopSeparator => "┳",
|
||||
BorderPart.HeaderTopRight => "┓",
|
||||
BorderPart.HeaderLeft => "┃",
|
||||
BorderPart.HeaderSeparator => "┃",
|
||||
BorderPart.HeaderRight => "┃",
|
||||
BorderPart.HeaderBottomLeft => "┣",
|
||||
BorderPart.HeaderBottom => "━",
|
||||
BorderPart.HeaderBottomSeparator => "╋",
|
||||
BorderPart.HeaderBottomRight => "┫",
|
||||
BorderPart.CellLeft => "┃",
|
||||
BorderPart.CellSeparator => "┃",
|
||||
BorderPart.CellRight => "┃",
|
||||
BorderPart.FooterBottomLeft => "┗",
|
||||
BorderPart.FooterBottom => "━",
|
||||
BorderPart.FooterBottomSeparator => "┻",
|
||||
BorderPart.FooterBottomRight => "┛",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/Spectre.Console/Borders/HeavyEdgeBorder.cs
Normal file
40
src/Spectre.Console/Borders/HeavyEdgeBorder.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a border with a heavy edge.
|
||||
/// </summary>
|
||||
public sealed class HeavyEdgeBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override Border? SafeBorder => Border.Square;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => "┏",
|
||||
BorderPart.HeaderTop => "━",
|
||||
BorderPart.HeaderTopSeparator => "┯",
|
||||
BorderPart.HeaderTopRight => "┓",
|
||||
BorderPart.HeaderLeft => "┃",
|
||||
BorderPart.HeaderSeparator => "│",
|
||||
BorderPart.HeaderRight => "┃",
|
||||
BorderPart.HeaderBottomLeft => "┠",
|
||||
BorderPart.HeaderBottom => "─",
|
||||
BorderPart.HeaderBottomSeparator => "┼",
|
||||
BorderPart.HeaderBottomRight => "┨",
|
||||
BorderPart.CellLeft => "┃",
|
||||
BorderPart.CellSeparator => "│",
|
||||
BorderPart.CellRight => "┃",
|
||||
BorderPart.FooterBottomLeft => "┗",
|
||||
BorderPart.FooterBottom => "━",
|
||||
BorderPart.FooterBottomSeparator => "┷",
|
||||
BorderPart.FooterBottomRight => "┛",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/Spectre.Console/Borders/HeavyHeadBorder.cs
Normal file
40
src/Spectre.Console/Borders/HeavyHeadBorder.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a border with a heavy header.
|
||||
/// </summary>
|
||||
public sealed class HeavyHeadBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override Border? SafeBorder => Border.Square;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => "┏",
|
||||
BorderPart.HeaderTop => "━",
|
||||
BorderPart.HeaderTopSeparator => "┳",
|
||||
BorderPart.HeaderTopRight => "┓",
|
||||
BorderPart.HeaderLeft => "┃",
|
||||
BorderPart.HeaderSeparator => "┃",
|
||||
BorderPart.HeaderRight => "┃",
|
||||
BorderPart.HeaderBottomLeft => "┡",
|
||||
BorderPart.HeaderBottom => "━",
|
||||
BorderPart.HeaderBottomSeparator => "╇",
|
||||
BorderPart.HeaderBottomRight => "┩",
|
||||
BorderPart.CellLeft => "│",
|
||||
BorderPart.CellSeparator => "│",
|
||||
BorderPart.CellRight => "│",
|
||||
BorderPart.FooterBottomLeft => "└",
|
||||
BorderPart.FooterBottom => "─",
|
||||
BorderPart.FooterBottomSeparator => "┴",
|
||||
BorderPart.FooterBottomRight => "┘",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spectre.Console/Borders/HorizontalBorder.cs
Normal file
37
src/Spectre.Console/Borders/HorizontalBorder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a horizontal border.
|
||||
/// </summary>
|
||||
public sealed class HorizontalBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => "─",
|
||||
BorderPart.HeaderTop => "─",
|
||||
BorderPart.HeaderTopSeparator => "─",
|
||||
BorderPart.HeaderTopRight => "─",
|
||||
BorderPart.HeaderLeft => " ",
|
||||
BorderPart.HeaderSeparator => " ",
|
||||
BorderPart.HeaderRight => " ",
|
||||
BorderPart.HeaderBottomLeft => "─",
|
||||
BorderPart.HeaderBottom => "─",
|
||||
BorderPart.HeaderBottomSeparator => "─",
|
||||
BorderPart.HeaderBottomRight => "─",
|
||||
BorderPart.CellLeft => " ",
|
||||
BorderPart.CellSeparator => " ",
|
||||
BorderPart.CellRight => " ",
|
||||
BorderPart.FooterBottomLeft => "─",
|
||||
BorderPart.FooterBottom => "─",
|
||||
BorderPart.FooterBottomSeparator => "─",
|
||||
BorderPart.FooterBottomRight => "─",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spectre.Console/Borders/MinimalBorder.cs
Normal file
37
src/Spectre.Console/Borders/MinimalBorder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a minimal border.
|
||||
/// </summary>
|
||||
public sealed class MinimalBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => " ",
|
||||
BorderPart.HeaderTop => " ",
|
||||
BorderPart.HeaderTopSeparator => " ",
|
||||
BorderPart.HeaderTopRight => " ",
|
||||
BorderPart.HeaderLeft => " ",
|
||||
BorderPart.HeaderSeparator => "│",
|
||||
BorderPart.HeaderRight => " ",
|
||||
BorderPart.HeaderBottomLeft => " ",
|
||||
BorderPart.HeaderBottom => "─",
|
||||
BorderPart.HeaderBottomSeparator => "┼",
|
||||
BorderPart.HeaderBottomRight => " ",
|
||||
BorderPart.CellLeft => " ",
|
||||
BorderPart.CellSeparator => "│",
|
||||
BorderPart.CellRight => " ",
|
||||
BorderPart.FooterBottomLeft => " ",
|
||||
BorderPart.FooterBottom => " ",
|
||||
BorderPart.FooterBottomSeparator => " ",
|
||||
BorderPart.FooterBottomRight => " ",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spectre.Console/Borders/MinimalDoubleHeadBorder.cs
Normal file
37
src/Spectre.Console/Borders/MinimalDoubleHeadBorder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a minimal border with a double header border.
|
||||
/// </summary>
|
||||
public sealed class MinimalDoubleHeadBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => " ",
|
||||
BorderPart.HeaderTop => " ",
|
||||
BorderPart.HeaderTopSeparator => " ",
|
||||
BorderPart.HeaderTopRight => " ",
|
||||
BorderPart.HeaderLeft => " ",
|
||||
BorderPart.HeaderSeparator => "│",
|
||||
BorderPart.HeaderRight => " ",
|
||||
BorderPart.HeaderBottomLeft => " ",
|
||||
BorderPart.HeaderBottom => "═",
|
||||
BorderPart.HeaderBottomSeparator => "╪",
|
||||
BorderPart.HeaderBottomRight => " ",
|
||||
BorderPart.CellLeft => " ",
|
||||
BorderPart.CellSeparator => "│",
|
||||
BorderPart.CellRight => " ",
|
||||
BorderPart.FooterBottomLeft => " ",
|
||||
BorderPart.FooterBottom => " ",
|
||||
BorderPart.FooterBottomSeparator => " ",
|
||||
BorderPart.FooterBottomRight => " ",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/Spectre.Console/Borders/MinimalHeavyHeadBorder.cs
Normal file
40
src/Spectre.Console/Borders/MinimalHeavyHeadBorder.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a minimal border with a heavy header.
|
||||
/// </summary>
|
||||
public sealed class MinimalHeavyHeadBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override Border? SafeBorder => Border.Minimal;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => " ",
|
||||
BorderPart.HeaderTop => " ",
|
||||
BorderPart.HeaderTopSeparator => " ",
|
||||
BorderPart.HeaderTopRight => " ",
|
||||
BorderPart.HeaderLeft => " ",
|
||||
BorderPart.HeaderSeparator => "│",
|
||||
BorderPart.HeaderRight => " ",
|
||||
BorderPart.HeaderBottomLeft => " ",
|
||||
BorderPart.HeaderBottom => "━",
|
||||
BorderPart.HeaderBottomSeparator => "┿",
|
||||
BorderPart.HeaderBottomRight => " ",
|
||||
BorderPart.CellLeft => " ",
|
||||
BorderPart.CellSeparator => "│",
|
||||
BorderPart.CellRight => " ",
|
||||
BorderPart.FooterBottomLeft => " ",
|
||||
BorderPart.FooterBottom => " ",
|
||||
BorderPart.FooterBottomSeparator => " ",
|
||||
BorderPart.FooterBottomRight => " ",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ namespace Spectre.Console.Rendering
|
||||
/// </summary>
|
||||
public sealed class NoBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override bool Visible => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
@@ -7,6 +7,9 @@ namespace Spectre.Console.Rendering
|
||||
/// </summary>
|
||||
public sealed class RoundedBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override Border? SafeBorder { get; } = Border.Square;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
37
src/Spectre.Console/Borders/SimpleBorder.cs
Normal file
37
src/Spectre.Console/Borders/SimpleBorder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a simple border.
|
||||
/// </summary>
|
||||
public sealed class SimpleBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => " ",
|
||||
BorderPart.HeaderTop => " ",
|
||||
BorderPart.HeaderTopSeparator => " ",
|
||||
BorderPart.HeaderTopRight => " ",
|
||||
BorderPart.HeaderLeft => " ",
|
||||
BorderPart.HeaderSeparator => " ",
|
||||
BorderPart.HeaderRight => " ",
|
||||
BorderPart.HeaderBottomLeft => "─",
|
||||
BorderPart.HeaderBottom => "─",
|
||||
BorderPart.HeaderBottomSeparator => "─",
|
||||
BorderPart.HeaderBottomRight => "─",
|
||||
BorderPart.CellLeft => " ",
|
||||
BorderPart.CellSeparator => " ",
|
||||
BorderPart.CellRight => " ",
|
||||
BorderPart.FooterBottomLeft => " ",
|
||||
BorderPart.FooterBottom => " ",
|
||||
BorderPart.FooterBottomSeparator => " ",
|
||||
BorderPart.FooterBottomRight => " ",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/Spectre.Console/Borders/SimpleHeavyBorder.cs
Normal file
40
src/Spectre.Console/Borders/SimpleHeavyBorder.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a simple border with heavy lines.
|
||||
/// </summary>
|
||||
public sealed class SimpleHeavyBorder : Border
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override Border? SafeBorder => Border.Simple;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override string GetBoxPart(BorderPart part)
|
||||
{
|
||||
return part switch
|
||||
{
|
||||
BorderPart.HeaderTopLeft => " ",
|
||||
BorderPart.HeaderTop => " ",
|
||||
BorderPart.HeaderTopSeparator => " ",
|
||||
BorderPart.HeaderTopRight => " ",
|
||||
BorderPart.HeaderLeft => " ",
|
||||
BorderPart.HeaderSeparator => " ",
|
||||
BorderPart.HeaderRight => " ",
|
||||
BorderPart.HeaderBottomLeft => "━",
|
||||
BorderPart.HeaderBottom => "━",
|
||||
BorderPart.HeaderBottomSeparator => "━",
|
||||
BorderPart.HeaderBottomRight => "━",
|
||||
BorderPart.CellLeft => " ",
|
||||
BorderPart.CellSeparator => " ",
|
||||
BorderPart.CellRight => " ",
|
||||
BorderPart.FooterBottomLeft => " ",
|
||||
BorderPart.FooterBottom => " ",
|
||||
BorderPart.FooterBottomSeparator => " ",
|
||||
BorderPart.FooterBottomRight => " ",
|
||||
_ => throw new InvalidOperationException("Unknown box part."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,17 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
public bool SupportsAnsi { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not
|
||||
/// the console support links.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// There is probably a lot of room for improvement here
|
||||
/// once we have more information about the terminal
|
||||
/// we're running inside.
|
||||
/// </remarks>
|
||||
public bool SupportLinks => SupportsAnsi && !LegacyConsole;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color system.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Generated 2020-08-03 15:17
|
||||
// Generated 2020-09-18 10:42
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user