TextWrapper
ConsoleMonster.Text
Word wrapping and end/middle truncation in terminal cells, preserving graphemes and styles.
Inheritance
- object
- TextWrapper
Methods
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
- Styled line.
- width int
- Maximum cells; non-positive values produce an empty line.
- ellipsis string = "…"
- Marker, clipped to the budget on grapheme boundaries.
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
- width int
- profile ConsoleMonster.Text.TerminalWidthProfile
- ellipsis string = "…"
Returns
StyledLinepublic static string Truncate(string text, int width, string ellipsis = "…") #Truncates plain text at the end without splitting a grapheme.
Parameters
- text string
- Plain text.
- width int
- Maximum cells.
- ellipsis string = "…"
- 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
- width int
- profile ConsoleMonster.Text.TerminalWidthProfile
- ellipsis string = "…"
Returns
stringpublic 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
- Plain text.
- width int
- Maximum cells.
- ellipsis string = "…"
- 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
- width int
- profile ConsoleMonster.Text.TerminalWidthProfile
- ellipsis string = "…"
Returns
stringpublic 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
- Styled line.
- width int
- Maximum cells.
- ellipsis string = "…"
- Marker inserted between the retained ends.
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
- Styled line.
- width int
- Maximum cells per line; values below one use one.
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
- width int
- profile ConsoleMonster.Text.TerminalWidthProfile
Returns
IReadOnlyList<StyledLine>