| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- ---
- title: ASCIIFont
- description: Display text using ASCII art fonts
- order: 14
- ---
- # ASCIIFont
- Display text using ASCII art fonts with multiple font styles available. Great for titles, headers, and decorative text.
- ## Basic Usage
- ### Renderable API
- ```typescript
- import { ASCIIFontRenderable, RGBA, createCliRenderer } from "@opentui/core"
- const renderer = await createCliRenderer()
- const title = new ASCIIFontRenderable(renderer, {
- id: "title",
- text: "OPENTUI",
- font: "tiny",
- color: RGBA.fromInts(255, 255, 255, 255),
- })
- renderer.root.add(title)
- ```
- ### Construct API
- ```typescript
- import { ASCIIFont, createCliRenderer } from "@opentui/core"
- const renderer = await createCliRenderer()
- renderer.root.add(
- ASCIIFont({
- text: "HELLO",
- font: "block",
- color: "#00FF00",
- }),
- )
- ```
- ## Available Fonts
- OpenTUI includes several ASCII art font styles:
- ```typescript
- // 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"
- }
- ```
- ## Positioning
- Position the ASCII text anywhere on screen:
- ```typescript
- const title = new ASCIIFontRenderable(renderer, {
- id: "title",
- text: "TITLE",
- font: "block",
- color: RGBA.fromHex("#FFFF00"),
- x: 10,
- y: 2,
- })
- ```
- ## Properties
- | Property | Type | Default | Description |
- | ----------------- | ---------------------------- | --------------- | -------------------------- |
- | `text` | `string` | `""` | Text to display |
- | `font` | `ASCIIFontName` | `"tiny"` | Font style to use |
- | `color` | `ColorInput \| ColorInput[]` | `"#FFFFFF"` | Text color(s) |
- | `backgroundColor` | `ColorInput` | `"transparent"` | Background color |
- | `selectable` | `boolean` | `true` | Whether text is selectable |
- | `selectionBg` | `ColorInput` | - | Selection background color |
- | `selectionFg` | `ColorInput` | - | Selection foreground color |
- | `x` | `number` | - | X position offset |
- | `y` | `number` | - | Y position offset |
- ## Example: Welcome Screen
- ```typescript
- import { Box, ASCIIFont, Text, createCliRenderer } from "@opentui/core"
- const renderer = await createCliRenderer()
- const welcomeScreen = Box(
- {
- width: "100%",
- height: "100%",
- flexDirection: "column",
- alignItems: "center",
- justifyContent: "center",
- },
- ASCIIFont({
- text: "OPENTUI",
- font: "huge",
- color: "#00FFFF",
- }),
- Text({
- content: "Terminal UI Framework",
- fg: "#888888",
- }),
- Text({
- content: "Press any key to continue...",
- fg: "#444444",
- }),
- )
- renderer.root.add(welcomeScreen)
- ```
- ## Dynamic Text
- Update the text content dynamically:
- ```typescript
- 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 gradient-like effects by positioning multiple ASCII fonts:
- ```typescript
- import { Box, ASCIIFont } from "@opentui/core"
- const gradientTitle = Box(
- {},
- ASCIIFont({
- text: "HELLO",
- font: "block",
- color: "#FF0000",
- }),
- // Overlay with offset for shadow effect
- ASCIIFont({
- text: "HELLO",
- font: "block",
- color: "#880000",
- left: 1,
- top: 1,
- }),
- )
- ```
|