FrameBufferRenderable provides a way to use custom graphics buffers within OpenTUI’s layout system. It wraps an OptimizedBuffer that you can draw to directly, enabling advanced rendering techniques and custom graphics.
Import
Basic Usage
Props
number
required
Initial width of the frame buffer in columns.
number
required
Initial height of the frame buffer in rows.
boolean
default:"false"
Whether to respect alpha transparency when compositing the buffer. When
true, transparent pixels allow content behind to show through.Properties
frameBuffer
Access to the underlyingOptimizedBuffer for direct drawing operations:
OptimizedBuffer documentation for complete drawing API.
Methods
Automatic Resizing
The frame buffer automatically resizes when the component’s dimensions change:flexGrow, flexShrink, etc.
Examples
Custom Graphics Canvas
Pixel Art Display
Chart Renderer
Double-Buffered Animation
Off-screen Rendering
Use Cases
- Custom visualizations - Charts, graphs, plots
- Pixel art - Retro graphics and sprites
- Image rendering - Display processed images or photos
- Canvas drawing - Freeform graphics and shapes
- Game graphics - Sprites, tiles, and game elements
- Performance - Batch drawing operations for complex scenes
Performance Considerations
- Frame buffers store complete pixel data, so large buffers use more memory
- Drawing to a frame buffer is efficient - changes only trigger re-render when
requestRender()is called - Use
respectAlpha: falsewhen transparency is not needed for better performance - Consider buffer size relative to terminal dimensions
Lifecycle
- The internal buffer is automatically resized when component dimensions change
- The buffer is properly cleaned up when the component is destroyed
- Call
requestRender()after drawing operations to trigger a visual update
Notes
- The frame buffer uses the same
widthMethodas the render context for consistent character width handling - Resizing to invalid dimensions (≤ 0) throws an error
- The component is visible by default and participates in normal layout
- Use standard Renderable props for positioning, sizing, and layout
Source
View the full source code atpackages/core/src/renderables/FrameBuffer.ts:11