Added MaxWidthLine into the TextFormatter class.

This commit is contained in:
BDisp
2022-09-06 14:17:54 +01:00
parent d368215e07
commit 2c9421c153
2 changed files with 22 additions and 0 deletions

View File

@@ -835,6 +835,18 @@ namespace Terminal.Gui {
return max;
}
/// <summary>
/// Determines the line with the highest width in the
/// <paramref name="text"/> if it contains newlines.
/// </summary>
/// <param name="text">Text, may contain newlines.</param>
/// <returns>The highest line width.</returns>
public static int MaxWidthLine (ustring text)
{
var result = TextFormatter.SplitNewLine (text);
return result.Max (x => x.ConsoleWidth);
}
/// <summary>
/// Gets the total width of the passed text.
/// </summary>

View File

@@ -4054,5 +4054,15 @@ e
Assert.Equal ("Third Line 界", splited [2]);
Assert.Equal ("", splited [^1]);
}
[Fact]
public void MaxWidthLine_With_And_Without_Newlines ()
{
var text = "Single Line 界";
Assert.Equal (14, TextFormatter.MaxWidthLine (text));
text = $"First Line 界\nSecond Line 界\nThird Line 界\n";
Assert.Equal (14, TextFormatter.MaxWidthLine (text));
}
}
}