Represents a renderable segment.
Constructors
public Segment(string text)
Initializes a new instance of the Segment class.
Parameters:
text (string)Properties
Empty
: SegmentGets an empty segment.
IsControlCode
: boolGets a value indicating whether or not this is a control code such as cursor movement.
IsLineBreak
: boolGets a value indicating whether or not this is an explicit line break that should be preserved.
IsWhiteSpace
: boolGets a value indicating whether or not this is a whitespace that should be preserved but not taken into account when layouting text.
LineBreak
: SegmentGets a segment representing a line break.
Text
: stringGets the segment text.
Methods
public int CellCount()
Gets the number of cells that this segment occupies in the console.
Returns:
The number of cells that this segment occupies in the console.
public static int CellCount(IEnumerable<Segment> segments)
Gets the number of cells that the segments occupies in the console.
Parameters:
segments (IEnumerable<Segment>)Returns:
The number of cells that the segments occupies in the console.
public Segment Clone()
Clones the segment.
Returns:
A new segment that's identical to this one.
public static Segment Control(string control)
Creates a control segment.
Parameters:
control (string)Returns:
A segment representing a control code.
public static Segment Padding(int size)
Creates padding segment.
Parameters:
size (int)Returns:
Segment for specified padding size.
public ValueTuple<Segment, Segment> Split(int offset)
Splits the segment at the offset.
Parameters:
offset (int)Returns:
One or two new segments representing the split.
public static List<SegmentLine> SplitLines(IEnumerable<Segment> segments)
Splits the provided segments into lines.
Parameters:
segments (IEnumerable<Segment>)Returns:
A collection of lines.
public static List<SegmentLine> SplitLines(IEnumerable<Segment> segments, int maxWidth, int? height = default)
Splits the provided segments into lines with a maximum width.
Parameters:
segments (IEnumerable<Segment>)maxWidth (int)height (int?)Returns:
A list of lines.
public static List<Segment> SplitOverflow(Segment segment, Overflow? overflow, int maxWidth)
Splits an overflowing segment into several new segments.
Parameters:
segment (Segment)overflow (Overflow?)maxWidth (int)Returns:
A list of segments that has been split.
public Segment StripLineEndings()
Returns a new segment without any trailing line endings.
Returns:
A new segment without any trailing line endings.
public static List<Segment> Truncate(IEnumerable<Segment> segments, int maxWidth)
Truncates the segments to the specified width.
Parameters:
segments (IEnumerable<Segment>)maxWidth (int)Returns:
A list of segments that has been truncated.
public static Segment Truncate(Segment segment, int maxWidth)
Truncates the segment to the specified width.
Parameters:
segment (Segment)maxWidth (int)Returns:
A new truncated segment, or null.