Expose extension method that gets the cell width of text

This commit is contained in:
Patrik Svensson 2021-08-28 23:22:53 +02:00 committed by Patrik Svensson
parent 48d49d6e18
commit 8cfe06e77a
2 changed files with 7 additions and 2 deletions

View File

@ -59,7 +59,12 @@ namespace Spectre.Console
return result.ToString(); return result.ToString();
} }
internal static int CellLength(this string text) /// <summary>
/// Gets the cell width of the specified text.
/// </summary>
/// <param name="text">The text to get the cell width of.</param>
/// <returns>The cell width of the text.</returns>
public static int GetCellWidth(this string text)
{ {
return Cell.GetCellLength(text); return Cell.GetCellLength(text);
} }

View File

@ -423,7 +423,7 @@ namespace Spectre.Console.Rendering
var builder = new StringBuilder(); var builder = new StringBuilder();
foreach (var character in segment.Text) foreach (var character in segment.Text)
{ {
var accumulatedCellWidth = builder.ToString().CellLength(); var accumulatedCellWidth = builder.ToString().GetCellWidth();
if (accumulatedCellWidth >= maxWidth) if (accumulatedCellWidth >= maxWidth)
{ {
break; break;