Class TextFormatter
Provides text formatting capabilities for console apps. Supports, hotkeys, horizontal alignment, multiple lines, and word-based line wrap.
public class TextFormatter
- Inheritance
-
TextFormatter
- Inherited Members
Properties
- Alignment
Controls the horizontal text-alignment property.
- AutoSize
Used by Text to resize the view's Bounds with the Size. Setting AutoSize to true only work if the Width and Height are null or Absolute values and doesn't work with Computed layout, to avoid breaking the Pos and Dim settings.
- CursorPosition
Gets the cursor position from HotKey. If the HotKey is defined, the cursor will be positioned over it.
- Direction
Controls the text-direction property.
- HotKey
Gets the hotkey. Will be an upper case letter or digit.
- HotKeyPos
The position in the text of the hotkey. The hotkey will be rendered using the hot color.
- HotKeySpecifier
The specifier character for the hotkey (e.g. '_'). Set to '\xffff' to disable hotkey support for this View instance. The default is '\xffff'.
- Lines
Gets the formatted lines.
- NeedsFormat
Gets or sets whether the TextFormatter needs to format the text when Draw(Rect, Attribute, Attribute, Rect, bool) is called. If it is
false
when Draw is called, the Draw call will be faster.
- PreserveTrailingSpaces
Gets or sets a flag that determines whether Text will have trailing spaces preserved or not when WordWrap(ustring, int, bool, int, TextDirection) is enabled. If
true
any trailing spaces will be trimmed when either the Text property is changed or when WordWrap(ustring, int, bool, int, TextDirection) is set totrue
. The default isfalse
.
- Size
Gets or sets the size of the area the text will be constrained to when formatted.
- Text
The text to be displayed. This text is never modified.
- VerticalAlignment
Controls the vertical text-alignment property.
Methods
- CalcRect(int, int, ustring, TextDirection)
Calculates the rectangle required to hold text, assuming no word wrapping.
- ClipAndJustify(ustring, int, bool, TextDirection)
Justifies text within a specified width.
- ClipAndJustify(ustring, int, TextAlignment, TextDirection)
Justifies text within a specified width.
- ClipOrPad(string, int)
Adds trailing whitespace or truncates
text
so that it fits exactlywidth
console units. Note that some unicode characters take 2+ columns
- Draw(Rect, Attribute, Attribute, Rect, bool)
Draws the text held by TextFormatter to Driver using the colors specified.
- FindHotKey(ustring, Rune, bool, out int, out Key)
Finds the hotkey and its location in text.
- Format(ustring, int, bool, bool, bool, int, TextDirection)
Reformats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries.
- Format(ustring, int, TextAlignment, bool, bool, int, TextDirection)
Reformats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries.
- GetMaxColsForWidth(List<ustring>, int)
Gets the index position from the list based on the
width
.
- GetMaxLengthForWidth(ustring, int)
Gets the index position from the text based on the
width
.
- GetMaxLengthForWidth(List<Rune>, int)
Gets the index position from the list based on the
width
.
- GetSumMaxCharWidth(ustring, int, int)
Gets the maximum characters width from the text based on the
startIndex
and thelength
.
- GetSumMaxCharWidth(List<ustring>, int, int)
Gets the maximum characters width from the list based on the
startIndex
and thelength
.
- GetTextWidth(ustring)
Gets the total width of the passed text.
- 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(ustring, int, char, TextDirection)
Justifies the text to fill the width provided. Space will be added between words (demarked by spaces and tabs) to make the text just fit
width
. Spaces will not be added to the ends.
- MaxLines(ustring, int)
Computes the number of lines needed to render the specified text given the width.
- MaxWidth(ustring, int)
Computes the maximum width needed to render the text (single line or multiple lines) given a minimum width.
- MaxWidthLine(ustring)
Determines the line with the highest width in the
text
if it contains newlines.
- RemoveHotKeySpecifier(ustring, int, Rune)
Removes the hotkey specifier from text.
- ReplaceHotKeyWithTag(ustring, int)
Replaces the Rune at the index specified by the
hotPos
parameter with a tag identifying it as the hotkey.
- SplitNewLine(ustring)
Splits all newlines in the
text
into a list and supports both CRLF and LF, preserving the ending newline.
- WordWrap(ustring, int, bool, int, TextDirection)
Formats the provided text to fit within the width provided using word wrapping.
Events
- HotKeyChanged
Event invoked when the HotKey is changed.