sdk/apps/cli/.agents/skills/opentui/references/components/text-display.md
Components for displaying text content in OpenTUI.
The primary component for displaying styled text.
// React/Solid
<text>Hello, World!</text>
// With content prop
<text content="Hello, World!" />
// Core
const text = new TextRenderable(renderer, {
id: "greeting",
content: "Hello, World!",
})
For React and Solid, use nested modifier tags for text styling:
<text fg="#FFFFFF" bg="#000000">
<strong>Bold</strong>, <em>italic</em>, and <u>underlined</u>
</text>
Important: Do NOT use
bold,italic,underline,dim,strikethroughas props on<text>— they don't work. Always use nested tags like<strong>,<em>,<u>, or<span>with styling.
import { TextRenderable, TextAttributes } from "@opentui/core"
const text = new TextRenderable(renderer, {
content: "Styled",
attributes: TextAttributes.BOLD | TextAttributes.UNDERLINE,
})
Available attributes:
TextAttributes.BOLDTextAttributes.DIMTextAttributes.ITALICTextAttributes.UNDERLINETextAttributes.BLINKTextAttributes.INVERSETextAttributes.HIDDENTextAttributes.STRIKETHROUGH<text selectable>
This text can be selected by the user
</text>
<text selectable={false}>
This text cannot be selected
</text>
For copy-on-selection and the full selection API, see keyboard/REFERENCE.md (selection).
Inline styling elements that must be used inside <text>:
Inline styled text:
<text>
Normal text with <span fg="red">red text</span> inline
</text>
<text>
<strong>Bold text</strong>
<b>Also bold</b>
</text>
<text>
<em>Italic text</em>
<i>Also italic</i>
</text>
<text>
<u>Underlined text</u>
</text>
<text>
Line one
Line two
</text>
<text>
Visit <a href="https://example.com">our website</a>
</text>
<text>
<span fg="#00FF00">
<strong>Bold green</strong>
</span>
and
<span fg="#FF0000">
<em><u>italic underlined red</u></em>
</span>
</text>
The t template literal for complex styling:
import { t, bold, italic, underline, fg, bg, dim } from "@opentui/core"
const styled = t`
${bold("Bold")} and ${italic("italic")} text.
${fg("#FF0000")("Red text")} with ${bg("#0000FF")("blue background")}.
${dim("Dimmed")} and ${underline("underlined")}.
`
const text = new TextRenderable(renderer, {
content: styled,
})
| Function | Description |
|---|---|
bold(text) | Bold text |
italic(text) | Italic text |
underline(text) | Underlined text |
dim(text) | Dimmed text |
strikethrough(text) | Strikethrough text |
fg(color)(text) | Set foreground color |
bg(color)(text) | Set background color |
Display large ASCII art text banners.
// React
<ascii-font text="TITLE" font="tiny" />
// Solid
<ascii_font text="TITLE" font="tiny" />
// Core
const title = new ASCIIFontRenderable(renderer, {
id: "title",
text: "TITLE",
font: "tiny",
})
| Font | Description |
|---|---|
tiny | Compact ASCII font |
block | Block-style letters |
slick | Sleek modern style |
shade | Shaded 3D effect |
// React
<ascii-font
text="HELLO"
font="block"
color="#00FF00"
/>
// Core
import { RGBA } from "@opentui/core"
const title = new ASCIIFontRenderable(renderer, {
text: "HELLO",
font: "block",
color: RGBA.fromHex("#00FF00"),
})
Font: tiny
╭─╮╭─╮╭─╮╭╮╭╮╭─╮╶╮╶ ╶╮
│ ││─┘├┤ │╰╯││ │ │
╰─╯╵ ╰─╯╵ ╵╰─╯╶╯╶╰─╯
Font: block
█▀▀█ █▀▀█ █▀▀ █▀▀▄
█ █ █▀▀▀ █▀▀ █ █
▀▀▀▀ ▀ ▀▀▀ ▀ ▀
// Hex colors
<text fg="#FF0000">Red</text>
<text fg="#F00">Short hex</text>
// Named colors
<text fg="red">Red</text>
<text fg="blue">Blue</text>
// Transparent
<text bg="transparent">No background</text>
The RGBA class from @opentui/core can be used in all frameworks (Core, React, Solid) for programmatic color manipulation:
import { RGBA } from "@opentui/core"
// From hex string (most common)
const red = RGBA.fromHex("#FF0000")
const shortHex = RGBA.fromHex("#F00") // Short form supported
// From integers (0-255 range for each channel)
const green = RGBA.fromInts(0, 255, 0, 255) // r, g, b, a
const semiGreen = RGBA.fromInts(0, 255, 0, 128) // 50% transparent
// From normalized floats (0.0-1.0 range)
const blue = RGBA.fromValues(0.0, 0.0, 1.0, 1.0) // r, g, b, a
const overlay = RGBA.fromValues(0.1, 0.1, 0.1, 0.7) // Dark semi-transparent
// Common use cases
const backgroundColor = RGBA.fromHex("#1a1a2e")
const textColor = RGBA.fromHex("#FFFFFF")
const borderColor = RGBA.fromInts(122, 162, 247, 255) // Tokyo Night blue
const shadowColor = RGBA.fromValues(0.0, 0.0, 0.0, 0.5) // 50% black
When to use each method:
fromHex() - When working with design specs or CSS colorsfromInts() - When you have 8-bit color values (0-255)fromValues() - When doing color math or interpolation (normalized 0.0-1.0)// React or Solid - RGBA works with color props
import { RGBA } from "@opentui/core"
const primaryColor = RGBA.fromHex("#7aa2f7")
function MyComponent() {
return (
<box backgroundColor={primaryColor} borderColor={primaryColor}>
<text fg={RGBA.fromHex("#c0caf5")}>Styled with RGBA</text>
</box>
)
}
Most props that accept color strings ("#FF0000", "red") also accept RGBA objects directly.
Text wraps based on parent container:
<box width={40}>
<text>
This long text will wrap when it reaches the edge of the
40-character wide parent container.
</text>
</box>
function Counter() {
const [count, setCount] = useState(0)
return <text>Count: {count}</text>
}
function Counter() {
const [count, setCount] = createSignal(0)
return <text>Count: {count()}</text>
}
const text = new TextRenderable(renderer, {
id: "counter",
content: "Count: 0",
})
// Update later
text.setContent("Count: 1")
// WRONG - modifiers only work inside <text>
<box>
<strong>Won't work</strong>
</box>
// CORRECT
<box>
<text>
<strong>This works</strong>
</text>
</box>
// May cause layout issues
<text></text>
// Better - use space or conditional
<text>{content || " "}</text>
// WRONG
<text fg="FF0000">Missing #</text>
// CORRECT
<text fg="#FF0000">With #</text>