Basic Usage
Props
Widget identifier for debugging.
Canvas width in terminal columns.
Canvas height in terminal rows.
Drawing callback invoked every frame with a fresh canvas context.
Rendering mode. One of:
"auto"- Auto-detect best available mode (braille or ascii)"braille"- 2×4 sub-cell dots (highest resolution)"sextant"- 2×3 sub-cell blocks"quadrant"- 2×2 sub-cell blocks"halfblock"- 1×2 sub-cell blocks"ascii"- 1×1 cell fallback
Canvas Context API
Thedraw callback receives a CanvasContext with the following methods:
Drawing Primitives
line(x0, y0, x1, y1, color)
Draw a line from (x0, y0) to (x1, y1).
polyline(points, color)
Draw connected line segments through multiple points.
fillRect(x, y, w, h, color)
Draw a filled rectangle.
strokeRect(x, y, w, h, color)
Draw a rectangle outline.
roundedRect(x, y, w, h, radius, color)
Draw a rounded rectangle outline.
circle(cx, cy, radius, color)
Draw a circle outline.
fillCircle(cx, cy, radius, color)
Draw a filled circle.
arc(cx, cy, radius, startAngle, endAngle, color)
Draw an arc outline. Angles in radians.
fillTriangle(x0, y0, x1, y1, x2, y2, color)
Draw a filled triangle.
setPixel(x, y, color)
Set a single pixel.
text(x, y, str, color?)
Draw text overlay at canvas coordinates. Text renders in terminal cells above the canvas.
clear(color?)
Clear the canvas. If color is omitted, clears to transparent.
Color Format
Colors can be:- Hex strings:
"#3b82f6","#f00" - Theme color names (resolved via context):
"accent.primary","fg.primary"
Blitter Modes
Braille (2×4)
Highest resolution mode using Unicode braille characters. Each terminal cell represents an 8-dot grid.Best for: Line charts, scatter plots, smooth curves
Sextant (2×3)
Block characters with 6 sub-cell regions.Best for: Bar charts, heatmaps, filled regions
Quadrant (2×2)
Block characters with 4 sub-cell quadrants.Best for: Pixel art, simple graphics
Halfblock (1×2)
Upper/lower half-block characters.Best for: Horizontal bar charts, timelines
ASCII (1×1)
Fallback mode using solid block character█. No sub-cell resolution.
Best for: Maximum compatibility, simple diagrams
Examples
Line Graph
Animated Spinner
Heatmap Grid
Shape Showcase
Performance
The canvas re-renders every frame. For static graphics, consider:- Caching computed paths in state
- Using conditional rendering to skip frames
- Preferring built-in chart widgets when possible
Terminal Compatibility
All blitter modes work in all terminals, but visual quality varies:| Terminal | Braille | Sextant | Quadrant | Halfblock | ASCII |
|---|---|---|---|---|---|
| Kitty | ✓ | ✓ | ✓ | ✓ | ✓ |
| WezTerm | ✓ | ✓ | ✓ | ✓ | ✓ |
| iTerm2 | ✓ | ✓ | ✓ | ✓ | ✓ |
| Windows Terminal | ✓ | ✓ | ✓ | ✓ | ✓ |
| xterm | ✓ | ✓ | ✓ | ✓ | ✓ |
| Basic TTY | - | - | - | - | ✓ |
blitter: "auto" to automatically select the best available mode.
See Also
- Line Chart - Built-in line chart widget
- Scatter Plot - Built-in scatter plot widget
- Heatmap - Built-in heatmap widget
- Image - Display images using graphics protocols