mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Added MaxWidthLine into the TextFormatter class.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user