Skip to content
ConsoleMonster

API Reference

Class

TextWrapper

Namespace ConsoleMonster.Text
Assembly ConsoleMonster
Modifiers static

Word wrapping and end/middle truncation in terminal cells, preserving graphemes and styles.

Inheritance

  • Object
  • TextWrapper

Methods

Truncate 4 overloads
public static StyledLine Truncate(StyledLine line, Int32 width, String ellipsis = "…") #
Returns: StyledLine

Truncates a styled line at the end, appending an ellipsis when text was cut.

Parameters

line ConsoleMonster.Text.StyledLine requiredposition: 0
Styled line.
width System.Int32 requiredposition: 1
Maximum cells; non-positive values produce an empty line.
ellipsis System.String = "…" optionalposition: 2
Marker, clipped to the budget on grapheme boundaries.

Returns

A line no wider than the budget, with retained text styles.

public static StyledLine Truncate(StyledLine line, Int32 width, TerminalWidthProfile profile, String ellipsis = "…") #
Returns: StyledLine

Truncates a styled line using an explicit width profile.

Parameters

line ConsoleMonster.Text.StyledLine requiredposition: 0
width System.Int32 requiredposition: 1
profile ConsoleMonster.Text.TerminalWidthProfile requiredposition: 2
ellipsis System.String = "…" optionalposition: 3
public static String Truncate(String text, Int32 width, String ellipsis = "…") #
Returns: String

Truncates plain text at the end without splitting a grapheme.

Parameters

text System.String requiredposition: 0
Plain text.
width System.Int32 requiredposition: 1
Maximum cells.
ellipsis System.String = "…" optionalposition: 2
Marker appended when text is cut.

Returns

Text within the budget.

public static String Truncate(String text, Int32 width, TerminalWidthProfile profile, String ellipsis = "…") #
Returns: String

Truncates plain text with an explicit width profile.

Parameters

text System.String requiredposition: 0
width System.Int32 requiredposition: 1
profile ConsoleMonster.Text.TerminalWidthProfile requiredposition: 2
ellipsis System.String = "…" optionalposition: 3
TruncateMiddle 3 overloads
public static String TruncateMiddle(String text, Int32 width, String ellipsis = "…") #
Returns: String

Truncates the middle of text, retaining both the beginning and the end (useful for paths).

Parameters

text System.String requiredposition: 0
Plain text.
width System.Int32 requiredposition: 1
Maximum cells.
ellipsis System.String = "…" optionalposition: 2
Marker inserted between the retained ends.

Returns

Text within the budget, on grapheme boundaries.

public static String TruncateMiddle(String text, Int32 width, TerminalWidthProfile profile, String ellipsis = "…") #
Returns: String

Truncates the middle using an explicit width profile.

Parameters

text System.String requiredposition: 0
width System.Int32 requiredposition: 1
profile ConsoleMonster.Text.TerminalWidthProfile requiredposition: 2
ellipsis System.String = "…" optionalposition: 3
public static StyledLine TruncateMiddle(StyledLine line, Int32 width, String ellipsis = "…") #
Returns: StyledLine

Truncates the middle of a styled line, keeping both ends and their styles; the marker takes the style of the text before it.

Parameters

line ConsoleMonster.Text.StyledLine requiredposition: 0
Styled line.
width System.Int32 requiredposition: 1
Maximum cells.
ellipsis System.String = "…" optionalposition: 2
Marker inserted between the retained ends.

Returns

A line within the budget, on grapheme boundaries.

Wrap 2 overloads
public static IReadOnlyList<StyledLine> Wrap(StyledLine line, Int32 width) #
Returns: IReadOnlyList<StyledLine>

Word-wraps a line, keeping inner spaces and trimming spaces at breaks. Lines break after a space when one fits; otherwise after a separator (\ / ; , | & ? before . - : =, keeping a path segment or list item whole when it fits), so the line ends with it; only then by character. An indivisible grapheme wider than the budget becomes a space.

Parameters

line ConsoleMonster.Text.StyledLine requiredposition: 0
Styled line.
width System.Int32 requiredposition: 1
Maximum cells per line; values below one use one.

Returns

At least one line, each within the budget.

public static IReadOnlyList<StyledLine> Wrap(StyledLine line, Int32 width, TerminalWidthProfile profile) #
Returns: IReadOnlyList<StyledLine>

Word-wraps a line using an explicit terminal width profile.

Parameters

line ConsoleMonster.Text.StyledLine requiredposition: 0
width System.Int32 requiredposition: 1
profile ConsoleMonster.Text.TerminalWidthProfile requiredposition: 2

Fields

public const String Ellipsis #

The ellipsis used by Full and Basic glyph tiers.

Value: …