Add support for column alignment and padding

Closes #12
Closes #31
This commit is contained in:
Patrik Svensson
2020-08-08 01:52:54 +02:00
committed by Patrik Svensson
parent fa85216554
commit 2dd0eb9f74
16 changed files with 543 additions and 243 deletions

View File

@ -17,6 +17,11 @@ namespace Spectre.Console.Internal
public static string NormalizeLineEndings(this string text, bool native = false)
{
if (text == null)
{
return null;
}
var normalized = text?.Replace("\r\n", "\n")
?.Replace("\r", string.Empty);

View File

@ -14,7 +14,7 @@ namespace Spectre.Console.Internal
{
ratios = ratios.Zip(maximums, (a, b) => (ratio: a, max: b)).Select(a => a.max > 0 ? a.ratio : 0).ToList();
var totalRatio = ratios.Sum();
if (totalRatio == 0)
if (totalRatio <= 0)
{
return values;
}
@ -24,9 +24,9 @@ namespace Spectre.Console.Internal
foreach (var (ratio, maximum, value) in ratios.Zip(maximums, values))
{
if (ratio > 0 && totalRatio > 0)
if (ratio != 0 && totalRatio > 0)
{
var distributed = (int)Math.Min(maximum, Math.Round(ratio * totalRemaining / (double)totalRatio));
var distributed = (int)Math.Min(maximum, Math.Round((double)(ratio * totalRemaining / totalRatio)));
result.Add(value - distributed);
totalRemaining -= distributed;
totalRatio -= ratio;