Overview
TheText widget displays text content with support for multiple formats including plain text, Markdown rendering, and syntax-highlighted code.
Constructor
TextOptions
The text content to display. Can be updated later using
setContent().Content format:
"plain"- Plain text (default)"markdown"- Render as Markdown with formatting"code"- Syntax-highlighted code (requireslanguage)
Programming language for syntax highlighting when
format is "code".Examples: "javascript", "rust", "python", "json", etc.Foreground (text) color. Accepts:
- Hex string:
"#FF0000" - Color name:
"red","blue", etc. - 256-color code:
196
Background color. Same format as
fg.Enable bold text styling.
Enable italic text styling.
Enable underline text styling.
Methods
setContent()
Update the text content.The new text content to display.
ts/src/widgets/text.ts:43
getContent()
Retrieve the current text content.The current text content.
ts/src/widgets/text.ts:49
setCodeLanguage()
Set the programming language for syntax highlighting (only applies when format is"code").
Programming language identifier (e.g.,
"rust", "javascript").ts/src/widgets/text.ts:60
Examples
Inherited Methods
Text inherits all methods from the Widget base class, including:setVisible(visible)- Control visibilitysetWidth(width)- Set width constraintsetHeight(height)- Set height constraintdestroy()- Clean up resourcesanimate(options)- Animate properties
Notes
- Text widgets are leaf nodes and cannot have children
- Markdown rendering supports common formatting (headings, bold, italic, lists, etc.)
- Syntax highlighting uses the same engine as popular code editors
- Content can be updated dynamically using
setContent()without recreating the widget - Text styling properties (
bold,italic,underline) can be combined