Table of Contents

Class TextView

Namespace
Terminal.Gui
Assembly
Terminal.Gui.dll

Multi-line text editing View.

public class TextView : View, IDisposable, ISupportInitializeNotification, ISupportInitialize
Inheritance
TextView
Implements
Inherited Members

Remarks

TextView provides a multi-line text editor. Users interact with it with the standard Windows, Mac, and Linux (Emacs) commands.

ShortcutAction performed
Left cursor, Control-bMoves the editing point left.
Right cursor, Control-fMoves the editing point right.
Alt-bMoves one word back.
Alt-fMoves one word forward.
Up cursor, Control-pMoves the editing point one line up.
Down cursor, Control-nMoves the editing point one line down
Home key, Control-aMoves the cursor to the beginning of the line.
End key, Control-eMoves the cursor to the end of the line.
Control-HomeScrolls to the first line and moves the cursor there.
Control-EndScrolls to the last line and moves the cursor there.
Delete, Control-dDeletes the character in front of the cursor.
BackspaceDeletes the character behind the cursor.
Control-k Deletes the text until the end of the line and replaces the kill buffer with the deleted text. You can paste this text in a different place by using Control-y.
Control-yPastes the content of the kill ring into the current position.
Alt-d Deletes the word above the cursor and adds it to the kill ring. You can paste the contents of the kill ring with Control-y.
Control-q Quotes the next input character, to prevent the normal processing of key handling to take place.

Constructors

TextView()

Initializes a TextView on the specified area, with dimensions controlled with the X, Y, Width and Height properties.

Properties

AllowsReturn

Gets or sets whether pressing ENTER in a TextView creates a new line of text in the view or invokes the Accepting event.

AllowsTab

Gets or sets whether the TextView inserts a tab character into the text or ignores tab input. If set to false and the user presses the tab key (or shift-tab) the focus will move to the next view (or previous with shift-tab). The default is true; if the user presses the tab key, a tab character will be inserted into the text.

Autocomplete

Provides autocomplete context menu based on suggestions at the current cursor position. Configure SuggestionGenerator to enable this feature

ContextMenu

Get the ContextMenu for this view.

CurrentColumn

Gets the cursor column.

CurrentRow

Gets the current cursor row.

CursorPosition

Sets or gets the current cursor position.

HasHistoryChanges

Indicates whatever the text has history changes or not. true if the text has history changes false otherwise.

InheritsPreviousAttribute

If true and the current Attribute is null will inherit from the previous, otherwise if false (default) do nothing. If the text is load with Load(List<Cell>) this property is automatically sets to true.

IsDirty

Indicates whatever the text was changed or not. true if the text was changed false otherwise.

IsSelecting

Get or sets whether the user is currently selecting text.

LeftColumn

Gets or sets the left column.

Lines

Gets the number of lines.

Maxlength

Gets the maximum visible length line.

Multiline

Gets or sets a value indicating whether this TextView is a multiline text view.

ReadOnly

Gets or sets whether the TextView is in read-only mode or not

SelectedCellsList

Gets the selected text as List{List{Cell}}

SelectedLength

Length of the selected text.

SelectedText

The selected text.

SelectionStartColumn

Start column position of the selected text.

SelectionStartRow

Start row position of the selected text.

TabWidth

Gets or sets a value indicating the number of whitespace when pressing the TAB key.

Text

Sets or gets the text in the TextView.

TopRow

Gets or sets the top row.

Used

Tracks whether the text view should be considered "used", that is, that the user has moved in the entry, so new input should be appended at the cursor position, rather than clearing the entry

WordWrap

Allows word wrap the to fit the available container width.

Methods

ClearHistoryChanges()

Allows clearing the HistoryText.HistoryTextItemEventArgs items updating the original text.

CloseFile()

Closes the contents of the stream into the TextView.

Copy()

Copy the selected text to the clipboard contents.

Cut()

Cut the selected text to the clipboard contents.

DeleteAll()

Deletes all text.

DeleteCharLeft()

Deletes all the selected or a single character at left from the position of the cursor.

DeleteCharRight()

Deletes all the selected or a single character at right from the position of the cursor.

FindNextText(string, out bool, bool, bool, string?, bool)

Find the next text based on the match case with the option to replace it.

FindPreviousText(string, out bool, bool, bool, string?, bool)

Find the previous text based on the match case with the option to replace it.

FindTextChanged()

Reset the flag to stop continuous find.

GetAllLines()

Gets all lines of characters.

GetCurrentLine()

Returns the characters on the current line (where the cursor is positioned). Use CurrentColumn to determine the position of the cursor within that line

GetLine(int)

Returns the characters on the line.

GetNormalColor()

Determines the current ColorScheme based on the Enabled value.

InsertText(string)

Inserts the given toAdd text at the current cursor position exactly as if the user had just typed it

Load(List<List<Cell>>)

Loads the contents of the list of Cell list into the TextView.

Load(List<Cell>)

Loads the contents of the Cell list into the TextView.

Load(Stream)

Loads the contents of the stream into the TextView.

Load(string)

Loads the contents of the file into the TextView.

MoveEnd()

Will scroll the TextView to the last line and position the cursor there.

MoveHome()

Will scroll the TextView to the first line and position the cursor there.

OnContentsChanged()

Called when the contents of the TextView change. E.g. when the user types text or deletes text. Raises the ContentsChanged event.

OnDrawNormalColor(List<Cell>, int, int)

Sets the Driver to an appropriate color for rendering the given idxCol of the current line. Override to provide custom coloring by calling SetAttribute(Attribute) Defaults to Normal.

OnDrawReadOnlyColor(List<Cell>, int, int)

Sets the Driver to an appropriate color for rendering the given idxCol of the current line. Override to provide custom coloring by calling SetAttribute(Attribute) Defaults to Focus.

OnDrawSelectionColor(List<Cell>, int, int)

Sets the Driver to an appropriate color for rendering the given idxCol of the current line. Override to provide custom coloring by calling SetAttribute(Attribute) Defaults to Focus.

OnDrawUsedColor(List<Cell>, int, int)

Sets the Driver to an appropriate color for rendering the given idxCol of the current line. Override to provide custom coloring by calling SetAttribute(Attribute) Defaults to HotFocus.

OnDrawingContent()

Called when the View's content is to be drawn. The default implementation does nothing.

OnHasFocusChanged(bool, View?, View?)

Invoked after HasFocus has changed. This method is called before the HasFocusChanged event is raised.

OnKeyDown(Key)

Called when the user presses a key, allowing subscribers to pre-process the key down event. Called before key bindings are invoked and KeyDownNotHandled is raised. Set Handled to true to stop the key from being processed further.

OnKeyDownNotHandled(Key)

Called when the user has pressed key it wasn't handled by KeyDown and was not bound to a key binding.

OnKeyUp(Key)

Called when a key is released. This method is called from NewKeyUpEvent(Key).

OnMouseEvent(MouseEventArgs)

Called when a mouse event occurs within the view's Viewport.

OnUnwrappedCursorPosition(int?, int?)

Invoke the UnwrappedCursorPosition event with the unwrapped CursorPosition.

Paste()

Paste the clipboard contents into the current selected position.

PositionCursor()

Positions the cursor on the current row and column

PromptForColors()

Open a dialog to set the foreground and background colors.

Redo()

Redoes the latest changes.

ReplaceAllText(string, bool, bool, string?)

Replaces all the text based on the match case.

ScrollTo(int, bool)

Will scroll the TextView to display the specified row at the top if isRow is true or will scroll the TextView to display the specified column at the left if isRow is false.

SelectAll()

Select all text.

SetNormalColor()

Sets the driver to the default color for the control where no text is being rendered. Defaults to Normal.

Undo()

Undoes the latest changes.

Events

ContentsChanged

Raised when the contents of the TextView are changed.

DrawNormalColor

Invoked when the normal color is drawn.

DrawReadOnlyColor

Invoked when the ready only color is drawn.

DrawSelectionColor

Invoked when the selection color is drawn.

DrawUsedColor

Invoked when the used color is drawn. The Used Color is used to indicate if the InsertChar was pressed and enabled.

UnwrappedCursorPosition

Invoked with the unwrapped CursorPosition.