Improve text composite

- A `Text` object should not be able to justify itself.
  All justification needs to be done by a parent.
- Apply colors and styles to part of a `Text` object
- Markup parser should return a `Text` object
This commit is contained in:
Patrik Svensson
2020-07-30 23:26:22 +02:00
committed by Patrik Svensson
parent 8e4f33bba4
commit f19202b427
33 changed files with 728 additions and 434 deletions

View File

@ -0,0 +1,18 @@
using System.Collections.Generic;
namespace Spectre.Console.Internal
{
internal static class AppearanceExtensions
{
public static Appearance Combine(this Appearance appearance, IEnumerable<Appearance> source)
{
var current = appearance;
foreach (var item in source)
{
current = current.Combine(item);
}
return current;
}
}
}

View File

@ -1,12 +0,0 @@
using System.Text;
namespace Spectre.Console.Internal
{
internal static class CharExtensions
{
public static int CellLength(this char token, Encoding encoding)
{
return Cell.GetCellLength(encoding, token);
}
}
}

View File

@ -1,6 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Spectre.Console.Composition;
namespace Spectre.Console.Internal
{

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Spectre.Console.Internal
{
internal static class EnumerableExtensions
{
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));
}
}
}