Class TextFormatter
Provides text formatting. Supports HotKeys, horizontal and vertical alignment, text direction, multiple lines, and word-based line wrap.
public class TextFormatter
- Inheritance
-
TextFormatter
- Inherited Members
Properties
- Alignment
Get or sets the horizontal text alignment.
- ConstrainToHeight
Gets or sets the height Text will be constrained to when formatted.
- ConstrainToSize
Gets or sets the width and height Text will be constrained to when formatted.
- ConstrainToWidth
Gets or sets the width Text will be constrained to when formatted.
- CursorPosition
Gets the cursor position of the HotKey. If the HotKey is defined, the cursor will be positioned over it.
- Direction
Gets or sets the text-direction.
- FillRemaining
Determines if the viewport width will be used or only the text width will be used, If true all the viewport area will be filled with whitespaces and the same background color showing a perfect rectangle.
- HotKey
Gets or sets the hot key. Fires the HotKeyChanged event.
- HotKeyPos
The position in the text of the hot key. The hot key will be rendered using the hot color.
- HotKeySpecifier
The specifier character for the hot key (e.g. '_'). Set to '\xffff' to disable hot key support for this View instance. The default is '\xffff'.
- MultiLine
Gets or sets a value indicating whether multi line is allowed.
- NeedsFormat
Gets or sets whether the TextFormatter needs to format the text.
- PreserveTrailingSpaces
Gets or sets whether trailing spaces at the end of word-wrapped lines are preserved or not when WordWrap is enabled. If true trailing spaces at the end of wrapped lines will be removed when Text is formatted for display. The default is false.
- TabWidth
Gets or sets the number of columns used for a tab.
- Text
The text to be formatted. This string is never modified.
- VerticalAlignment
Gets or sets the vertical text-alignment.
- WordWrap
Gets or sets whether word wrap will be used to fit Text to ConstrainToSize.
Methods
- ClipAndJustify(string, int, bool, TextDirection, int, TextFormatter?)
Justifies text within a specified width.
- ClipAndJustify(string, int, Alignment, TextDirection, int, TextFormatter?)
Justifies text within a specified width.
- ClipOrPad(string, int)
Adds trailing whitespace or truncates
text
so that it fits exactlywidth
columns. Note that some unicode characters take 2+ columns
- Draw(Rectangle, Attribute, Attribute, Rectangle, ConsoleDriver?)
Draws the text held by TextFormatter to ConsoleDriver using the colors specified.
- FindHotKey(string, Rune, out int, out Key, bool)
Finds the HotKey and its location in text.
- Format()
Returns the formatted text, constrained to ConstrainToSize.
- Format(string, int, bool, bool, bool, int, TextDirection, bool, TextFormatter?)
Formats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries.
- Format(string, int, Alignment, bool, bool, int, TextDirection, bool, TextFormatter?)
Formats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries.
- FormatAndGetSize(Size?)
Gets the size required to hold the formatted text, given the constraints placed by ConstrainToSize.
- GetColumnsRequiredForVerticalText(List<string>, int, int, int)
Returns the number of columns required to render
lines
oriented vertically.
- GetHotKeySpecifierLength(bool)
Gets the width or height of the HotKeySpecifier characters in the Text property.
- GetLengthThatFits(List<Rune>, int, int, TextDirection)
Gets the number of the Runes in a list of Runes that will fit in
width
.
- GetLengthThatFits(string, int, int, TextDirection)
Gets the number of the Runes in the text that will fit in
width
.
- GetLines()
Gets a list of formatted lines, constrained to ConstrainToSize.
- GetMaxColsForWidth(List<string>, int, int)
Gets the index position from the list based on the
width
.
- GetSumMaxCharWidth(string, int, int, int)
Gets the maximum number of columns from the text based on the
startIndex
and thelength
.
- GetWidestLineLength(string, int)
Returns the number of columns in the widest line in the text, without word wrap, accounting for wide-glyphs (uses GetColumns(string)).
text
if it contains newlines.
- IsHorizontalDirection(TextDirection)
Check if it is a horizontal direction
- IsLeftToRight(TextDirection)
Check if it is Left to Right direction
- IsTopToBottom(TextDirection)
Check if it is Top to Bottom direction
- IsVerticalDirection(TextDirection)
Check if it is a vertical direction
- Justify(string, int, char, TextDirection, int)
Justifies the text to fill the width provided. Space will be added between words to make the text just fit
width
. Spaces will not be added to the start or end.
- RemoveHotKeySpecifier(string, int, Rune)
Removes the hotkey specifier from text.
- ReplaceHotKeyWithTag(string, int)
Replaces the Rune at the index specified by the
hotPos
parameter with a tag identifying it as the hotkey.
- SplitNewLine(string)
Splits all newlines in the
text
into a list and supports both CRLF and LF, preserving the ending newline.
- WordWrapText(string, int, bool, int, TextDirection, TextFormatter?)
Formats the provided text to fit within the width provided using word wrapping.
Events
- HotKeyChanged
Event invoked when the HotKey is changed.