Overview
TheTextArea widget provides multi-line text editing capabilities with 2D cursor positioning and optional word wrapping. Itβs designed for longer text input like code editors or message composers.
Constructor
TextAreaOptions
Width of the textarea. Accepts:
- Number: fixed width in cells
- String: percentage (e.g.,
"50%") or"auto"
Height of the textarea. Accepts:
- Number: fixed height in rows
- String: percentage (e.g.,
"100%") or"auto"
Enable word wrapping. When
true, long lines wrap to the next line automatically.Default: false (horizontal scrolling)Foreground (text) color. Accepts:
- Hex string:
"#FF0000" - Color name:
"red","blue", etc. - 256-color code:
196
Background color. Same format as
fg.Border style. Valid values:
"none"- no border"single"- single-line border"double"- double-line border"rounded"- rounded corners"bold"- bold border
Methods
setValue()
Set the entire text content.The text content to set. Can include newlines (
\n) for multiple lines.ts/src/widgets/textarea.ts:30
getValue()
Get the current text content.The complete text content including newlines.
ts/src/widgets/textarea.ts:36
setCursor()
Set the 2D cursor position.Zero-based row number. Will be clamped to valid range
[0, lineCount-1].Zero-based column number. Will be clamped to line length.
ts/src/widgets/textarea.ts:47
getCursor()
Get the current cursor position.Object containing:
row- Zero-based row numbercol- Zero-based column number
ts/src/widgets/textarea.ts:54
getLineCount()
Get the total number of lines.Number of lines in the textarea. Always at least 1.
ts/src/widgets/textarea.ts:64
setWrap()
Enable or disable word wrapping.true to enable word wrapping, false for horizontal scrolling.ts/src/widgets/textarea.ts:70
Examples
Inherited Methods
TextArea inherits all methods from the Widget base class, including:setVisible(visible)- Control visibilitysetForeground(color)- Set text colorsetBackground(color)- Set background colorsetBorderStyle(style)- Change border styledestroy()- Clean up resources
Event Handling
TextArea widgets respond to keyboard events:- Key events - Character input, backspace, delete, newlines
- Navigation - Arrow keys, page up/down, home/end
- Editing - Cut, copy, paste (platform-dependent)
app.drainEvents() in your event loop.
Notes
- TextArea supports multi-line editing with 2D cursor positioning
- Cursor position is automatically clamped to valid ranges
- Word wrapping mode can be toggled at runtime using
setWrap() - Line count is updated automatically as content changes
- Use
setValue()to replace all content; content is preserved across render cycles - TextArea widgets cannot have children
- For single-line input, use Input instead