mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-17 17:32:50 +08:00
Make segments immutable
This commit is contained in:
parent
cd0d182f12
commit
2943535973
@ -15,7 +15,7 @@ namespace Spectre.Console.Rendering
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the segment text.
|
/// Gets the segment text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Text { get; private set; }
|
public string Text { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether or not this is an expicit line break
|
/// Gets a value indicating whether or not this is an expicit line break
|
||||||
@ -38,12 +38,12 @@ namespace Spectre.Console.Rendering
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a segment representing a line break.
|
/// Gets a segment representing a line break.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Segment LineBreak => new Segment(Environment.NewLine, Style.Plain, true);
|
public static Segment LineBreak { get; } = new Segment(Environment.NewLine, Style.Plain, true);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an empty segment.
|
/// Gets an empty segment.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Segment Empty => new Segment(string.Empty, Style.Plain, false);
|
public static Segment Empty { get; } = new Segment(string.Empty, Style.Plain, false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Segment"/> class.
|
/// Initializes a new instance of the <see cref="Segment"/> class.
|
||||||
@ -241,12 +241,10 @@ namespace Spectre.Console.Rendering
|
|||||||
// Same style?
|
// Same style?
|
||||||
if (previous.Style.Equals(segment.Style))
|
if (previous.Style.Equals(segment.Style))
|
||||||
{
|
{
|
||||||
// Modify the content of the previous segment
|
previous = new Segment(previous.Text + segment.Text, previous.Style);
|
||||||
previous.Text += segment.Text;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Push the current one to the results.
|
|
||||||
result.Add(previous);
|
result.Add(previous);
|
||||||
previous = segment;
|
previous = segment;
|
||||||
}
|
}
|
||||||
@ -260,6 +258,15 @@ namespace Spectre.Console.Rendering
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clones the segment.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A new segment that's identical to this one.</returns>
|
||||||
|
public Segment Clone()
|
||||||
|
{
|
||||||
|
return new Segment(Text, Style);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Splits an overflowing segment into several new segments.
|
/// Splits an overflowing segment into several new segments.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user