ASCIIFont
ASCIIFont draws short text with bundled ASCII art fonts. Use Text for normal labels and prose.
Availability
| Field | Availability |
|---|---|
| Package | @opentui/core |
| Core renderable | ASCIIFontRenderable |
| React | <ascii-font> (automatic) |
| Solid | <ascii_font> (automatic) |
| Status | Built in |
Basic usage
Renderable API
Available fonts
OpenTUI includes several ASCII art font styles:
// Small, compact font
{
font: "tiny"
}
// Block style font
{
font: "block"
}
// Shaded style font
{
font: "shade"
}
// Slick style font
{
font: "slick"
}
// Large font
{
font: "huge"
}
// Grid style font
{
font: "grid"
}
// Pallet style font
{
font: "pallet"
}The tiny font draws OPEN in two rows:
█▀█ █▀█ █▀▀ █▄ █
█▄█ █▀▀ ██▄ █ ▀█The block font draws the same text in six rows:
██████╗ ██████╗ ███████╗ ███╗ ██╗
██╔═══██╗ ██╔══██╗ ██╔════╝ ████╗ ██║
██║ ██║ ██████╔╝ █████╗ ██╔██╗ ██║
██║ ██║ ██╔═══╝ ██╔══╝ ██║╚██╗██║
╚██████╔╝ ██║ ███████╗ ██║ ╚████║
╚═════╝ ╚═╝ ╚══════╝ ╚═╝ ╚═══╝Positioning
ASCIIFont inherits the standard layout positioning options. To position it at coordinates relative to its parent, use absolute positioning with left and top:
const title = new ASCIIFontRenderable(renderer, {
id: "title",
text: "TITLE",
font: "block",
color: RGBA.fromHex("#FFFF00"),
position: "absolute",
left: 10,
top: 2,
})Properties
| Property | Type | Default | Description |
|---|---|---|---|
text | string | "" | Text to display |
font | ASCIIFontName | "tiny" | Font style |
color | ColorInput | ColorInput[] | "#FFFFFF" | Text color or color bands |
backgroundColor | ColorInput | "transparent" | Background color |
selectable | boolean | true | Whether text is selectable |
selectionBg | ColorInput | - | Selection background color |
selectionFg | ColorInput | - | Selection foreground color |
position | "relative" | "absolute" | "relative" | Effective positioning mode |
top | number, "auto", or percentage string | - | Top position offset |
right | number, "auto", or percentage string | - | Right position offset |
bottom | number, "auto", or percentage string | - | Bottom position offset |
left | number, "auto", or percentage string | - | Left position offset |
Example: welcome screen
Dynamic text
Update the text content dynamically:
const counter = new ASCIIFontRenderable(renderer, {
id: "counter",
text: "0",
font: "block",
color: RGBA.fromHex("#FF0000"),
})
let count = 0
setInterval(() => {
count++
counter.text = count.toString()
}, 1000)Color effects
Create a shadow by overlaying two ASCII fonts:
Related concepts
See Layout for positioning and Colors for accepted color values. Use FrameBuffer for graphics that need direct cell drawing.