Skip to content

Commit

Permalink
Expose extension method that gets the cell width of text
Browse files Browse the repository at this point in the history
  • Loading branch information
patriksvensson committed Sep 18, 2021
1 parent 48d49d6 commit 8cfe06e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Spectre.Console/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public static string RemoveMarkup(this string? text)
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Spectre.Console/Rendering/Segment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public static List<Segment> Truncate(IEnumerable<Segment> segments, int maxWidth
var builder = new StringBuilder();
foreach (var character in segment.Text)
{
var accumulatedCellWidth = builder.ToString().CellLength();
var accumulatedCellWidth = builder.ToString().GetCellWidth();
if (accumulatedCellWidth >= maxWidth)
{
break;
Expand Down

0 comments on commit 8cfe06e

Please sign in to comment.