mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add net5.0 target framework
This commit is contained in:

committed by
Patrik Svensson

parent
b1da5e7ba8
commit
380c6aca45
@ -31,7 +31,7 @@ namespace Spectre.Console.Internal
|
||||
}
|
||||
|
||||
var line = lines.Dequeue();
|
||||
line = line.Replace(" ---> ", string.Empty);
|
||||
line = line.ReplaceExact(" ---> ", string.Empty);
|
||||
|
||||
var match = _messageRegex.Match(line);
|
||||
if (!match.Success)
|
||||
|
@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
internal static class DayOfWeekExtensions
|
||||
{
|
||||
public static string GetAbbreviatedDayName(this DayOfWeek day, CultureInfo culture)
|
||||
{
|
||||
culture ??= CultureInfo.InvariantCulture;
|
||||
return culture.DateTimeFormat
|
||||
.GetAbbreviatedDayName(day)
|
||||
.Capitalize(culture);
|
||||
}
|
||||
|
||||
public static DayOfWeek GetNextWeekDay(this DayOfWeek day)
|
||||
{
|
||||
var next = (int)day + 1;
|
||||
if (next > (int)DayOfWeek.Saturday)
|
||||
{
|
||||
return DayOfWeek.Sunday;
|
||||
}
|
||||
|
||||
return (DayOfWeek)next;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
internal static class DictionaryExtensions
|
||||
{
|
||||
public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> tuple, out T1 key, out T2 value)
|
||||
{
|
||||
key = tuple.Key;
|
||||
value = tuple.Value;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
internal static class EnumerableExtensions
|
||||
{
|
||||
public static int GetCount<T>(this IEnumerable<T> source)
|
||||
{
|
||||
if (source is IList<T> list)
|
||||
{
|
||||
return list.Count;
|
||||
}
|
||||
|
||||
if (source is T[] array)
|
||||
{
|
||||
return array.Length;
|
||||
}
|
||||
|
||||
return source.Count();
|
||||
}
|
||||
|
||||
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||
{
|
||||
foreach (var item in source)
|
||||
{
|
||||
action(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AnyTrue(this IEnumerable<bool> source)
|
||||
{
|
||||
return source.Any(b => b);
|
||||
}
|
||||
|
||||
public static IEnumerable<(int Index, bool First, bool Last, T Item)> Enumerate<T>(this IEnumerable<T> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return Enumerate(source.GetEnumerator());
|
||||
}
|
||||
|
||||
public static IEnumerable<(int Index, bool First, bool Last, T Item)> Enumerate<T>(this IEnumerator<T> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
var first = true;
|
||||
var last = !source.MoveNext();
|
||||
T current;
|
||||
|
||||
for (var index = 0; !last; index++)
|
||||
{
|
||||
current = source.Current;
|
||||
last = !source.MoveNext();
|
||||
yield return (index, first, last, current);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<TResult> SelectIndex<T, TResult>(this IEnumerable<T> source, Func<T, int, TResult> func)
|
||||
{
|
||||
return source.Select((value, index) => func(value, index));
|
||||
}
|
||||
|
||||
public static IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst, TSecond>(
|
||||
this IEnumerable<TFirst> source, IEnumerable<TSecond> first)
|
||||
{
|
||||
return source.Zip(first, (first, second) => (first, second));
|
||||
}
|
||||
|
||||
public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(
|
||||
this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third)
|
||||
{
|
||||
return first.Zip(second, (a, b) => (a, b))
|
||||
.Zip(third, (a, b) => (a.a, a.b, b));
|
||||
}
|
||||
}
|
||||
}
|
@ -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,21 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
internal static class TextWriterExtensions
|
||||
{
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types")]
|
||||
public static bool IsStandardOut(this TextWriter writer)
|
||||
{
|
||||
try
|
||||
{
|
||||
return writer == System.Console.Out;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
@ -23,9 +24,19 @@ namespace Spectre.Console.Internal
|
||||
unchecked
|
||||
{
|
||||
return Math.Abs(
|
||||
link.GetHashCode() +
|
||||
GetLinkHashCode(link) +
|
||||
_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;
|
||||
|
||||
hex ??= string.Empty;
|
||||
hex = hex.Replace("#", string.Empty).Trim();
|
||||
hex = hex.ReplaceExact("#", string.Empty).Trim();
|
||||
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user