Fix figlet centering possibly throwing due to negative size (#1302)

This commit is contained in:
Ola Bäcker 2023-09-14 19:50:12 +02:00 committed by GitHub
parent f7befacd79
commit 037e109699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,8 +67,8 @@ public sealed class FigletText : Renderable, IHasJustification
} }
else if (alignment == Console.Justify.Center) else if (alignment == Console.Justify.Center)
{ {
var left = (maxWidth - lineWidth) / 2; var left = Math.Max(0, maxWidth - lineWidth) / 2;
var right = left + ((maxWidth - lineWidth) % 2); var right = left + (Math.Max(0, maxWidth - lineWidth) % 2);
yield return Segment.Padding(left); yield return Segment.Padding(left);
yield return line; yield return line;