mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00
Add net5.0 target framework
This commit is contained in:
parent
b1da5e7ba8
commit
380c6aca45
11
.github/workflows/ci.yaml
vendored
11
.github/workflows/ci.yaml
vendored
@ -21,7 +21,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.301' # SDK Version to use.
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -55,10 +55,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet 3.1.402
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.301
|
dotnet-version: 3.1.402
|
||||||
|
|
||||||
|
- name: Setup dotnet 5.0.100
|
||||||
|
uses: actions/setup-dotnet@v1
|
||||||
|
with:
|
||||||
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Integration Tests
|
- name: Integration Tests
|
||||||
shell: bash
|
shell: bash
|
||||||
|
2
.github/workflows/docs.yaml
vendored
2
.github/workflows/docs.yaml
vendored
@ -24,7 +24,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.301' # SDK Version to use.
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Publish
|
- name: Publish
|
||||||
shell: bash
|
shell: bash
|
||||||
|
20
.github/workflows/publish.yaml
vendored
20
.github/workflows/publish.yaml
vendored
@ -29,7 +29,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.301' # SDK Version to use.
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -64,10 +64,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet 3.1.402
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.301
|
dotnet-version: 3.1.402
|
||||||
|
|
||||||
|
- name: Setup dotnet 5.0.100
|
||||||
|
uses: actions/setup-dotnet@v1
|
||||||
|
with:
|
||||||
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -90,10 +95,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet 3.1.402
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.301
|
dotnet-version: 3.1.402
|
||||||
|
|
||||||
|
- name: Setup dotnet 5.0.100
|
||||||
|
uses: actions/setup-dotnet@v1
|
||||||
|
with:
|
||||||
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Publish
|
- name: Publish
|
||||||
shell: bash
|
shell: bash
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
||||||
<DefaultItemExcludes>$(DefaultItemExcludes);output\**;.gitignore</DefaultItemExcludes>
|
<DefaultItemExcludes>$(DefaultItemExcludes);output\**;.gitignore</DefaultItemExcludes>
|
||||||
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
|
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"isRoot": true,
|
"isRoot": true,
|
||||||
"tools": {
|
"tools": {
|
||||||
"cake.tool": {
|
"cake.tool": {
|
||||||
"version": "0.38.4",
|
"version": "1.0.0-rc0001",
|
||||||
"commands": [
|
"commands": [
|
||||||
"dotnet-cake"
|
"dotnet-cake"
|
||||||
]
|
]
|
||||||
@ -15,7 +15,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dotnet-example": {
|
"dotnet-example": {
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"commands": [
|
"commands": [
|
||||||
"dotnet-example"
|
"dotnet-example"
|
||||||
]
|
]
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Borders</Title>
|
<Title>Borders</Title>
|
||||||
<Description>Demonstrates the different kind of borders.</Description>
|
<Description>Demonstrates the different kind of borders.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Calendars</Title>
|
<Title>Calendars</Title>
|
||||||
<Description>Demonstrates how to render calendars.</Description>
|
<Description>Demonstrates how to render calendars.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Colors</Title>
|
<Title>Colors</Title>
|
||||||
<Description>Demonstrates how to use [yellow]c[/][red]o[/][green]l[/][blue]o[/][aqua]r[/][lime]s[/] in the console.</Description>
|
<Description>Demonstrates how to use [yellow]c[/][red]o[/][green]l[/][blue]o[/][aqua]r[/][lime]s[/] in the console.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Columns</Title>
|
<Title>Columns</Title>
|
||||||
<Description>Demonstrates how to render data into columns.</Description>
|
<Description>Demonstrates how to render data into columns.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Cursor</Title>
|
<Title>Cursor</Title>
|
||||||
<Description>Demonstrates how to move the cursor.</Description>
|
<Description>Demonstrates how to move the cursor.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Emojis</Title>
|
<Title>Emojis</Title>
|
||||||
<Description>Demonstrates how to render emojis.</Description>
|
<Description>Demonstrates how to render emojis.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Exceptions</Title>
|
<Title>Exceptions</Title>
|
||||||
<Description>Demonstrates how to render formatted exceptions.</Description>
|
<Description>Demonstrates how to render formatted exceptions.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Grids</Title>
|
<Title>Grids</Title>
|
||||||
<Description>Demonstrates how to render grids in a console.</Description>
|
<Description>Demonstrates how to render grids in a console.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Info</Title>
|
<Title>Info</Title>
|
||||||
<Description>Displays the capabilities of the current console.</Description>
|
<Description>Displays the capabilities of the current console.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Links</Title>
|
<Title>Links</Title>
|
||||||
<Description>Demonstrates how to render links in a console.</Description>
|
<Description>Demonstrates how to render links in a console.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Panels</Title>
|
<Title>Panels</Title>
|
||||||
<Description>Demonstrates how to render items in panels.</Description>
|
<Description>Demonstrates how to render items in panels.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Rules</Title>
|
<Title>Rules</Title>
|
||||||
<Description>Demonstrates how to render horizontal rules (lines).</Description>
|
<Description>Demonstrates how to render horizontal rules (lines).</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Tables</Title>
|
<Title>Tables</Title>
|
||||||
<Description>Demonstrates how to render tables in a console.</Description>
|
<Description>Demonstrates how to render tables in a console.</Description>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"projects": [ "src" ],
|
"projects": [ "src" ],
|
||||||
"sdk": {
|
"sdk": {
|
||||||
"version": "3.1.301",
|
"version": "5.0.100",
|
||||||
"rollForward": "latestPatch"
|
"rollForward": "latestPatch"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -69,11 +69,13 @@ namespace Spectre.Console.Internal
|
|||||||
return source.Select((value, index) => func(value, index));
|
return source.Select((value, index) => func(value, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !NET5_0
|
||||||
public static IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst, TSecond>(
|
public static IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst, TSecond>(
|
||||||
this IEnumerable<TFirst> source, IEnumerable<TSecond> first)
|
this IEnumerable<TFirst> source, IEnumerable<TSecond> first)
|
||||||
{
|
{
|
||||||
return source.Zip(first, (first, second) => (first, second));
|
return source.Zip(first, (first, second) => (first, second));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(
|
public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(
|
||||||
this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third)
|
this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third)
|
@ -1,3 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Spectre.Console.Internal;
|
||||||
|
using Spectre.Console.Rendering;
|
||||||
|
|
||||||
namespace Spectre.Console
|
namespace Spectre.Console
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -5,6 +13,11 @@ namespace Spectre.Console
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class StringExtensions
|
public static class StringExtensions
|
||||||
{
|
{
|
||||||
|
// Cache whether or not internally normalized line endings
|
||||||
|
// already are normalized. No reason to do yet another replace if it is.
|
||||||
|
private static readonly bool _alreadyNormalized
|
||||||
|
= Environment.NewLine.Equals("\n", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Escapes text so that it won’t be interpreted as markup.
|
/// Escapes text so that it won’t be interpreted as markup.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -18,8 +31,137 @@ namespace Spectre.Console
|
|||||||
}
|
}
|
||||||
|
|
||||||
return text
|
return text
|
||||||
.Replace("[", "[[")
|
.ReplaceExact("[", "[[")
|
||||||
.Replace("]", "]]");
|
.ReplaceExact("]", "]]");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static int CellLength(this string text, RenderContext context)
|
||||||
|
{
|
||||||
|
if (context is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Cell.GetCellLength(context, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string Capitalize(this string text, CultureInfo? culture = null)
|
||||||
|
{
|
||||||
|
if (text == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
culture ??= CultureInfo.InvariantCulture;
|
||||||
|
|
||||||
|
if (text.Length > 0 && char.IsLower(text[0]))
|
||||||
|
{
|
||||||
|
text = string.Format(culture, "{0}{1}", char.ToUpper(text[0], culture), text.Substring(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string NormalizeLineEndings(this string? text, bool native = false)
|
||||||
|
{
|
||||||
|
text = text?.ReplaceExact("\r\n", "\n");
|
||||||
|
text = text?.ReplaceExact("\r", string.Empty);
|
||||||
|
text ??= string.Empty;
|
||||||
|
|
||||||
|
if (native && !_alreadyNormalized)
|
||||||
|
{
|
||||||
|
text = text.ReplaceExact("\n", Environment.NewLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string[] SplitLines(this string text)
|
||||||
|
{
|
||||||
|
var result = text?.NormalizeLineEndings()?.Split(new[] { '\n' }, StringSplitOptions.None);
|
||||||
|
return result ?? Array.Empty<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string[] SplitWords(this string word, StringSplitOptions options = StringSplitOptions.None)
|
||||||
|
{
|
||||||
|
var result = new List<string>();
|
||||||
|
|
||||||
|
static string Read(StringBuffer reader, Func<char, bool> criteria)
|
||||||
|
{
|
||||||
|
var buffer = new StringBuilder();
|
||||||
|
while (!reader.Eof)
|
||||||
|
{
|
||||||
|
var current = reader.Peek();
|
||||||
|
if (!criteria(current))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.Append(reader.Read());
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var reader = new StringBuffer(word))
|
||||||
|
{
|
||||||
|
while (!reader.Eof)
|
||||||
|
{
|
||||||
|
var current = reader.Peek();
|
||||||
|
if (char.IsWhiteSpace(current))
|
||||||
|
{
|
||||||
|
var x = Read(reader, c => char.IsWhiteSpace(c));
|
||||||
|
if (options != StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
{
|
||||||
|
result.Add(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.Add(Read(reader, c => !char.IsWhiteSpace(c)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string Repeat(this string text, int count)
|
||||||
|
{
|
||||||
|
if (text is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 1)
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Concat(Enumerable.Repeat(text, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string ReplaceExact(this string text, string oldValue, string? newValue)
|
||||||
|
{
|
||||||
|
#if NET5_0
|
||||||
|
return text.Replace(oldValue, newValue, StringComparison.Ordinal);
|
||||||
|
#else
|
||||||
|
return text.Replace(oldValue, newValue);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool ContainsExact(this string text, string value)
|
||||||
|
{
|
||||||
|
#if NET5_0
|
||||||
|
return text.Contains(value, StringComparison.Ordinal);
|
||||||
|
#else
|
||||||
|
return text.Contains(value);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Spectre.Console
|
namespace Spectre.Console
|
||||||
{
|
{
|
||||||
@ -87,5 +88,26 @@ namespace Spectre.Console
|
|||||||
decoration: style.Decoration,
|
decoration: style.Decoration,
|
||||||
link: link);
|
link: link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static Style Combine(this Style style, IEnumerable<Style> source)
|
||||||
|
{
|
||||||
|
if (style is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(style));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source is null)
|
||||||
|
{
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
var current = style;
|
||||||
|
foreach (var item in source)
|
||||||
|
{
|
||||||
|
current = current.Combine(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace Spectre.Console.Internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
var line = lines.Dequeue();
|
var line = lines.Dequeue();
|
||||||
line = line.Replace(" ---> ", string.Empty);
|
line = line.ReplaceExact(" ---> ", string.Empty);
|
||||||
|
|
||||||
var match = _messageRegex.Match(line);
|
var match = _messageRegex.Match(line);
|
||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
|
@ -1,127 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Spectre.Console.Rendering;
|
|
||||||
|
|
||||||
namespace Spectre.Console.Internal
|
|
||||||
{
|
|
||||||
internal static class StringExtensions
|
|
||||||
{
|
|
||||||
// Cache whether or not internally normalized line endings
|
|
||||||
// already are normalized. No reason to do yet another replace if it is.
|
|
||||||
private static readonly bool _alreadyNormalized
|
|
||||||
= Environment.NewLine.Equals("\n", StringComparison.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
public static int CellLength(this string text, RenderContext context)
|
|
||||||
{
|
|
||||||
if (context is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Cell.GetCellLength(context, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string Capitalize(this string text, CultureInfo? culture = null)
|
|
||||||
{
|
|
||||||
if (text == null)
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
culture ??= CultureInfo.InvariantCulture;
|
|
||||||
|
|
||||||
if (text.Length > 0 && char.IsLower(text[0]))
|
|
||||||
{
|
|
||||||
text = string.Format(culture, "{0}{1}", char.ToUpper(text[0], culture), text.Substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string NormalizeLineEndings(this string text, bool native = false)
|
|
||||||
{
|
|
||||||
text ??= string.Empty;
|
|
||||||
|
|
||||||
var normalized = text?.Replace("\r\n", "\n")?.Replace("\r", string.Empty) ?? string.Empty;
|
|
||||||
if (native && !_alreadyNormalized)
|
|
||||||
{
|
|
||||||
normalized = normalized.Replace("\n", Environment.NewLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
return normalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string[] SplitLines(this string text)
|
|
||||||
{
|
|
||||||
var result = text?.NormalizeLineEndings()?.Split(new[] { '\n' }, StringSplitOptions.None);
|
|
||||||
return result ?? Array.Empty<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string[] SplitWords(this string word, StringSplitOptions options = StringSplitOptions.None)
|
|
||||||
{
|
|
||||||
var result = new List<string>();
|
|
||||||
|
|
||||||
static string Read(StringBuffer reader, Func<char, bool> criteria)
|
|
||||||
{
|
|
||||||
var buffer = new StringBuilder();
|
|
||||||
while (!reader.Eof)
|
|
||||||
{
|
|
||||||
var current = reader.Peek();
|
|
||||||
if (!criteria(current))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.Append(reader.Read());
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var reader = new StringBuffer(word))
|
|
||||||
{
|
|
||||||
while (!reader.Eof)
|
|
||||||
{
|
|
||||||
var current = reader.Peek();
|
|
||||||
if (char.IsWhiteSpace(current))
|
|
||||||
{
|
|
||||||
var x = Read(reader, c => char.IsWhiteSpace(c));
|
|
||||||
if (options != StringSplitOptions.RemoveEmptyEntries)
|
|
||||||
{
|
|
||||||
result.Add(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.Add(Read(reader, c => !char.IsWhiteSpace(c)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string Repeat(this string text, int count)
|
|
||||||
{
|
|
||||||
if (text is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(text));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count <= 0)
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 1)
|
|
||||||
{
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
return string.Concat(Enumerable.Repeat(text, count));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Spectre.Console.Internal
|
|
||||||
{
|
|
||||||
internal static class StyleExtensions
|
|
||||||
{
|
|
||||||
public static Style Combine(this Style style, IEnumerable<Style> source)
|
|
||||||
{
|
|
||||||
if (style is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(style));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (source is null)
|
|
||||||
{
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
var current = style;
|
|
||||||
foreach (var item in source)
|
|
||||||
{
|
|
||||||
current = current.Combine(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Spectre.Console.Internal
|
namespace Spectre.Console.Internal
|
||||||
{
|
{
|
||||||
@ -23,9 +24,19 @@ namespace Spectre.Console.Internal
|
|||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
return Math.Abs(
|
return Math.Abs(
|
||||||
link.GetHashCode() +
|
GetLinkHashCode(link) +
|
||||||
_random.Next(0, int.MaxValue));
|
_random.Next(0, int.MaxValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private static int GetLinkHashCode(string link)
|
||||||
|
{
|
||||||
|
#if NET5_0
|
||||||
|
return link.GetHashCode(StringComparison.Ordinal);
|
||||||
|
#else
|
||||||
|
return link.GetHashCode();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ namespace Spectre.Console.Internal
|
|||||||
error = null;
|
error = null;
|
||||||
|
|
||||||
hex ??= string.Empty;
|
hex ??= string.Empty;
|
||||||
hex = hex.Replace("#", string.Empty).Trim();
|
hex = hex.ReplaceExact("#", string.Empty).Trim();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -237,7 +237,7 @@ namespace Spectre.Console.Rendering
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Does the segment contain a newline?
|
// Does the segment contain a newline?
|
||||||
if (segment.Text.Contains("\n"))
|
if (segment.Text.ContainsExact("\n"))
|
||||||
{
|
{
|
||||||
// Is it a new line?
|
// Is it a new line?
|
||||||
if (segment.Text == "\n")
|
if (segment.Text == "\n")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -180,6 +180,15 @@ namespace Spectre.Console
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
|
int? GetLinkHashCode()
|
||||||
|
{
|
||||||
|
#if NET5_0
|
||||||
|
return Link?.GetHashCode(StringComparison.Ordinal);
|
||||||
|
#else
|
||||||
|
return Link?.GetHashCode();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
var hash = (int)2166136261;
|
var hash = (int)2166136261;
|
||||||
@ -189,7 +198,7 @@ namespace Spectre.Console
|
|||||||
|
|
||||||
if (Link != null)
|
if (Link != null)
|
||||||
{
|
{
|
||||||
hash = (hash * 16777619) ^ Link?.GetHashCode() ?? 0;
|
hash = (hash * 16777619) ^ GetLinkHashCode() ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Spectre.Console.Internal;
|
using Spectre.Console.Internal;
|
||||||
using Spectre.Console.Rendering;
|
using Spectre.Console.Rendering;
|
||||||
|
|
||||||
@ -8,6 +9,7 @@ namespace Spectre.Console
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A renderable piece of markup text.
|
/// A renderable piece of markup text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[SuppressMessage("Naming", "CA1724:Type names should not match namespaces")]
|
||||||
public sealed class Markup : Renderable, IAlignable, IOverflowable
|
public sealed class Markup : Renderable, IAlignable, IOverflowable
|
||||||
{
|
{
|
||||||
private readonly Paragraph _paragraph;
|
private readonly Paragraph _paragraph;
|
||||||
|
@ -96,7 +96,7 @@ namespace Spectre.Console
|
|||||||
|
|
||||||
private IEnumerable<Segment> GetTitleSegments(RenderContext context, string title, int width)
|
private IEnumerable<Segment> GetTitleSegments(RenderContext context, string title, int width)
|
||||||
{
|
{
|
||||||
title = title.NormalizeLineEndings().Replace("\n", " ").Trim();
|
title = title.NormalizeLineEndings().ReplaceExact("\n", " ").Trim();
|
||||||
var markup = new Markup(title, Style);
|
var markup = new Markup(title, Style);
|
||||||
return ((IRenderable)markup).Render(context.WithSingleLine(), width);
|
return ((IRenderable)markup).Render(context.WithSingleLine(), width);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user