Skip to content
ConsoleMonster
Class

TextWrapper

ConsoleMonster.Text

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, int width, string ellipsis = "…") #

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

Parameters

line ConsoleMonster.Text.StyledLine required
Styled line.
width int required
Maximum cells; non-positive values produce an empty line.
ellipsis string = "…" optional
Marker, clipped to the budget on grapheme boundaries.

Returns

StyledLine A line no wider than the budget, with retained text styles.
public static StyledLine Truncate(StyledLine line, int width, TerminalWidthProfile profile, string ellipsis = "…") #

Truncates a styled line using an explicit width profile.

Parameters

line ConsoleMonster.Text.StyledLine required
width int required
profile ConsoleMonster.Text.TerminalWidthProfile required
ellipsis string = "…" optional

Returns

StyledLine
public static string Truncate(string text, int width, string ellipsis = "…") #

Truncates plain text at the end without splitting a grapheme.

Parameters

text string required
Plain text.
width int required
Maximum cells.
ellipsis string = "…" optional
Marker appended when text is cut.

Returns

string Text within the budget.
public static string Truncate(string text, int width, TerminalWidthProfile profile, string ellipsis = "…") #

Truncates plain text with an explicit width profile.

Parameters

text string required
width int required
profile ConsoleMonster.Text.TerminalWidthProfile required
ellipsis string = "…" optional

Returns

string
TruncateMiddle 3 overloads
public static string TruncateMiddle(string text, int width, string ellipsis = "…") #

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

Parameters

text string required
Plain text.
width int required
Maximum cells.
ellipsis string = "…" optional
Marker inserted between the retained ends.

Returns

string Text within the budget, on grapheme boundaries.
public static string TruncateMiddle(string text, int width, TerminalWidthProfile profile, string ellipsis = "…") #

Truncates the middle using an explicit width profile.

Parameters

text string required
width int required
profile ConsoleMonster.Text.TerminalWidthProfile required
ellipsis string = "…" optional

Returns

string
public static StyledLine TruncateMiddle(StyledLine line, int width, string ellipsis = "…") #

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 required
Styled line.
width int required
Maximum cells.
ellipsis string = "…" optional
Marker inserted between the retained ends.

Returns

StyledLine A line within the budget, on grapheme boundaries.
Wrap 2 overloads
public static IReadOnlyList<StyledLine> Wrap(StyledLine line, int width) #

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 required
Styled line.
width int required
Maximum cells per line; values below one use one.

Returns

IReadOnlyList<StyledLine> At least one line, each within the budget.
public static IReadOnlyList<StyledLine> Wrap(StyledLine line, int width, TerminalWidthProfile profile) #

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

Parameters

line ConsoleMonster.Text.StyledLine required
width int required
profile ConsoleMonster.Text.TerminalWidthProfile required

Returns

IReadOnlyList<StyledLine>

Fields

public const string Ellipsis #

The ellipsis used by Full and Basic glyph tiers.

Value: …