Segment

Represents a renderable segment.

Represents a renderable segment.

Constructors

public Segment(string text)

Initializes a new instance of the Segment class.

Parameters:

text (string)
The segment text.

Properties

Empty : Segment

Gets an empty segment.

IsControlCode : bool

Gets a value indicating whether or not this is a control code such as cursor movement.

IsLineBreak : bool

Gets a value indicating whether or not this is an explicit line break that should be preserved.

IsWhiteSpace : bool

Gets a value indicating whether or not this is a whitespace that should be preserved but not taken into account when layouting text.

LineBreak : Segment

Gets a segment representing a line break.

Text : string

Gets 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>)
The segments to measure.

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)
The control code.

Returns:

A segment representing a control code.

public static Segment Padding(int size)

Creates padding segment.

Parameters:

size (int)
Number of whitespace characters.

Returns:

Segment for specified padding size.

public ValueTuple<Segment, Segment> Split(int offset)

Splits the segment at the offset.

Parameters:

offset (int)
The offset where to split the segment.

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>)
The segments to split.

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>)
The segments to split into lines.
maxWidth (int)
The maximum width.
height (int?)
The height (if any).

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)
The segment to split.
overflow (Overflow?)
The overflow strategy to use.
maxWidth (int)
The maximum width.

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>)
The segments to truncate.
maxWidth (int)
The maximum width that the segments may occupy.

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)
The segment to truncate.
maxWidth (int)
The maximum width that the segment may occupy.

Returns:

A new truncated segment, or null.