ConsoleForge 0.3.0
Elm-architecture TUI framework for .NET 8
Loading...
Searching...
No Matches
ConsoleForge.Widgets.TextArea Class Referencesealed

A multi-line text input widget. More...

Inheritance diagram for ConsoleForge.Widgets.TextArea:

Public Member Functions

void OnKeyEvent (KeyMsg key, Action< IMsg > dispatch)
 Process a key event and dispatch a TextAreaChangedMsg with the new document state.
void Render (IRenderContext ctx)
 Renders visible lines into the allocated region.
 TextArea ()
 Object-initializer constructor; all properties default.
 TextArea (IReadOnlyList< string >? lines=null, int cursorRow=0, int cursorCol=0, int scrollRow=0, int maxLines=0, Style? style=null)
 Positional constructor for inline usage.

Static Public Member Functions

static int ComputeScrollRow (int cursorRow, int viewportHeight, int currentScrollRow)
 Compute a new ScrollRow that keeps cursorRow within the visible viewport.

Properties

int CursorCol [get]
 Zero-based column of the cursor within the current line.
int CursorRow [get]
 Zero-based row of the cursor within Lines.
bool HasFocus [get, set]
 True when this widget holds keyboard focus.
SizeConstraint Height = SizeConstraint.Flex(1) [get]
 Height constraint used by the layout engine.
IReadOnlyList< string > Lines = [""] [get]
 Lines of text. Never null; empty list = empty document.
int MaxLines [get]
 Maximum number of lines allowed.
int ScrollRow [get]
 First line index rendered.
Style Style = Style.Default [get]
 Visual style for the text content. Inherits theme base style when unset.
SizeConstraint Width = SizeConstraint.Flex(1) [get]
 Width constraint used by the layout engine.

Detailed Description

A multi-line text input widget.

Cursor position and scroll state live in the model (all properties are { get; init; }) — use the TextAreaChangedMsg returned from OnKeyEvent to derive the next widget state via with.

Scroll — The widget renders lines [ScrollRow, ScrollRow + visibleHeight). Update ScrollRow in your model's Update handler; use ComputeScrollRow as a helper.

Line endings — All text is stored as a list of strings (one per logical line). The widget does not produce or consume
in its messages.

Constructor & Destructor Documentation

◆ TextArea()

ConsoleForge.Widgets.TextArea.TextArea ( IReadOnlyList< string >? lines = null,
int cursorRow = 0,
int cursorCol = 0,
int scrollRow = 0,
int maxLines = 0,
Style? style = null )

Positional constructor for inline usage.

Parameters
linesInitial line content. Null or empty → single empty line.
cursorRowInitial cursor row (clamped).
cursorColInitial cursor column (clamped).
scrollRowInitial vertical scroll offset.
maxLinesMax line count (0 = unlimited).
styleOptional visual style override.

Member Function Documentation

◆ ComputeScrollRow()

int ConsoleForge.Widgets.TextArea.ComputeScrollRow ( int cursorRow,
int viewportHeight,
int currentScrollRow )
static

Compute a new ScrollRow that keeps cursorRow within the visible viewport.

Call this from your model's Update handler when handling TextAreaChangedMsg and WindowResizeMsg.

Parameters
cursorRowThe cursor row after the edit.
viewportHeightNumber of visible rows in the TextArea's region.
currentScrollRowCurrent scroll offset.
Returns
Adjusted scroll row ensuring cursor is visible.

◆ OnKeyEvent()

void ConsoleForge.Widgets.TextArea.OnKeyEvent ( KeyMsg key,
Action< IMsg > dispatch )

Process a key event and dispatch a TextAreaChangedMsg with the new document state.

The model should replace this widget instance with one constructed from the message fields using with expressions.

Implements ConsoleForge.Layout.IFocusable.

◆ Render()

void ConsoleForge.Widgets.TextArea.Render ( IRenderContext ctx)

Renders visible lines into the allocated region.

Lines outside [ScrollRow, ScrollRow + height) are not drawn. When focused, the cursor position is highlighted with reverse-video.

Implements ConsoleForge.Layout.IWidget.

Property Documentation

◆ MaxLines

int ConsoleForge.Widgets.TextArea.MaxLines
get

Maximum number of lines allowed.

0 = unlimited. When at the limit, Enter is a no-op.

◆ ScrollRow

int ConsoleForge.Widgets.TextArea.ScrollRow
get

First line index rendered.

Used for vertical scrolling. Update via ComputeScrollRow when handling TextAreaChangedMsg.


The documentation for this class was generated from the following file:
  • src/ConsoleForge/Widgets/TextArea.cs