Skip to main content

Module render

Module render 

Source
Expand description

Terminal rendering system for TUI applications

Double buffering and efficient diff-based updates for optimal performance.

§Architecture

The rendering system is composed of:

ComponentDescriptionModule
BackendLow-level terminal I/O abstractionbackend
BufferDouble-buffered screen state(see Buffer)
CellIndividual terminal cell (char, colors, modifiers)(see Cell)
TerminalHigh-level diff-based renderer(see Terminal)
DiffEfficient buffer diffing algorithm(see diff)
ImagesKitty, iTerm2, and Sixel graphicsAvailable with image feature

§Quick Start

use revue::render::{Terminal, Buffer};

// Create terminal
let mut terminal = Terminal::new()?;

// Create buffer matching terminal size
let mut buffer = Buffer::new(terminal.size()?);

// Draw to buffer
buffer.set_string(0, 0, "Hello, World!", style);

// Render with diffing
terminal.draw(&buffer)?;

§Double Buffering

Revue uses double buffering for efficient rendering:

  1. Two buffers of the same size are allocated
  2. Each frame renders to the “back” buffer
  3. Buffers are compared to find minimal changes
  4. Only changed cells are written to the terminal
  5. Buffers are swapped for the next frame

§Cell Rendering

use revue::render::{Cell, Modifier};

// Create a styled cell
let cell = Cell::new('A')
    .fg(Color::Blue)
    .bg(Color::Black)
    .modifier(Modifier::BOLD);

§Image Support

use revue::render::image_protocol::KittyImage;

// Detect image support
if let Some(protocol) = KittyImage::detect() {
    // Render image
    protocol.draw_image(x, y, &image_data)?;
}

§Performance

  • Diff-based updates minimize terminal writes
  • Batch operations group multiple cell updates
  • ANSI escape sequences are cached
  • Terminal capabilities are detected once

Re-exports§

pub use backend::Backend;
pub use backend::BackendCapabilities;
pub use backend::CrosstermBackend;

Modules§

backend
Terminal backend abstraction

Structs§

BatchStats
Statistics for render batches
Buffer
A buffer holding the terminal state
Cell
A single cell in the terminal buffer
Change
A change to be applied to the terminal
Modifier
Modifier flags for cell styling (1 byte instead of 5)
RenderBatch
Batched render operations
Terminal
Terminal backend for rendering

Enums§

BufferError
Error type for buffer creation failures
RenderOp
A single render operation

Functions§

diff
Compute the differences between two buffers within specified dirty regions.
stdout_terminal
Create a terminal with stdout