Overview
TerminalBackend renders a Scene to an ANSI/Unicode string for terminal display. It uses:
- Braille characters (U+2800–U+28FF) for circles and diagonal lines
- Box-drawing characters for axes and grid lines
- Full-block characters (█) for filled rectangles
- ANSI 24-bit color for all elements
Usage
Constructor
new
Creates a new terminal backend with specified dimensions.
Number of terminal character columns (typically 80-200)
Number of terminal character rows (typically 24-60)
TerminalBackend
Example:
Methods
render_scene
Renders a Scene to an ANSI/Unicode string.
The scene to render
String - ANSI string with color codes and Unicode graphics
Example:
Rendering Layers
The terminal backend renders in three layers (front-to-back):- char_grid - Filled rectangles (█) and text characters
- line_char_grid - Box-drawing characters for axes/ticks
- braille - Dot-matrix characters for circles and diagonal lines
Coordinate Mapping
Scene coordinates are mapped to terminal coordinates:- Braille resolution: 2×4 dots per character cell
- Character resolution: 1×1 character per cell
- Box-drawing uses bitmask encoding (TOP=1, RIGHT=2, BOTTOM=4, LEFT=8)
Features
- Horizontal/vertical lines: Rendered with box-drawing characters (─, │, ┼, etc.)
- Diagonal lines: Rendered with Bresenham algorithm on braille grid
- Circles: Filled using braille dots
- Filled paths: Scanline-filled with braille dots (for Sankey, pie slices)
- Text: Rendered directly with character grid
- Rotated labels: Collision-avoided stacking for readability
Auto-detection
Terminal dimensions can be auto-detected:CLI Usage
The CLI supports terminal output with--terminal:
Limitations
- UpSetPlot is not supported in terminal mode
- No font size control (uses monospace terminal font)
- Limited color resolution compared to image formats
- Text rotation is approximated
Source
src/backend/terminal.rs