Table of Contents

Class TextFormatter

Namespace
Terminal.Gui
Assembly
Terminal.Gui.dll

Provides text formatting. Supports HotKeys, horizontal alignment, vertical alignment, multiple lines, and word-based line wrap.

public class TextFormatter
Inheritance
TextFormatter
Inherited Members

Properties

Alignment

Controls the horizontal text-alignment property.

AutoSize

Gets or sets whether the Size should be automatically changed to fit the Text.

CursorPosition

Gets the cursor position of the HotKey. If the HotKey is defined, the cursor will be positioned over it.

Direction

Controls the text-direction property.

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.

Size

Gets or sets the size Text will be constrained to when formatted.

TabWidth

Gets or sets the number of columns used for a tab.

Text

The text to be formatted. This string is never modified.

VerticalAlignment

Controls the vertical text-alignment property.

WordWrap

Gets or sets whether word wrap will be used to fit Text to Size.

Methods

CalcRect(int, int, string, TextDirection, int)

Calculates the rectangle required to hold text, assuming no word wrapping or justification.

ClipAndJustify(string, int, bool, TextDirection, int, TextFormatter)

Justifies text within a specified width.

ClipAndJustify(string, int, TextAlignment, TextDirection, int, TextFormatter)

Justifies text within a specified width.

ClipOrPad(string, int)

Adds trailing whitespace or truncates text so that it fits exactly width 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 Size.

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, TextAlignment, bool, bool, int, TextDirection, bool, TextFormatter)

Formats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries.

FormatAndGetSize()

Gets the size required to hold the formatted text, given the constraints placed by Size.

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.

GetLineCount(string, int)

Returns the number of lines needed to render the specified text given the width.

GetLines()

Gets a list of formatted lines, constrained to Size.

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 the length.

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.