Skip to main content

Module renderer

Module renderer 

Source
Expand description

Cell-diff renderer and terminal byte planner.

The renderer turns a desired RenderBuffer into the shortest safe sequence of terminal bytes it can produce for the configured Optimizations. Applications use it through crate::screen::Screen. The public cost module exposes sequence predictors.

§Diff pipeline

The renderer keeps a tracked current buffer (cur_buf) representing what it believes is on the terminal. The buffer flow first syncs touched desired cells into the renderer-owned staging buffer (back_buf), filtering unchanged cells. Rendering then prepares the frame, optionally applies scroll optimizations, transforms touched rows, and finalizes the pen/cursor state.

desired cells ─▶ sync_front ─▶ back_buf (actual changes)
                                     │
                                     ▼
cur_buf (tracked screen) ─────▶ row diff / scroll diff
                                     │
                                     ▼
                          cursor + pen planners ─▶ escape bytes
                                     │
                                     ▼
                        cur_buf updated to match terminal

§Cursor movement planning

Cursor movement is planned by byte cost before any bytes are materialized. Absolute mode seeds CUP and, for local moves, lets relative decompositions compete. Relative mode considers optional prefixes (none, carriage return, and in absolute mode home), then vertical and horizontal legs. Horizontal planning can use hardware tabs, CHT/CBT, CUF/CUB, literal backspace, or re-emitting matching cells as an overwrite advance. Forward tabs use the terminal’s true next tab stop, not a right-edge-clamped value, so a tab is never chosen unless it lands at or before the target column. Sequence predictors live in cost. The cursor planner owns cell-aware overwrite costs beside their emission walk.

from ─▶ prefix? ─▶ vertical leg ─▶ horizontal leg ─▶ to
         │             │                 │
         │             │                 ├─ CUF/CUB, BS, tabs, CHT/CBT
         │             └─ LF/CUD/CUU/RI/VPA
         └─ none / CR / HOME (when eligible)

§Pen and SGR state

The renderer tracks the active style (“pen”) alongside cursor position. Before emitting a cell it writes only the style difference needed from the current pen to the target cell style, including OSC 8 hyperlink open/close transitions. At frame end the pen is reset to default only if the terminal state is not already default.

§Tab stops

TabStops stores configurable horizontal tab stops and precomputes previous, clamped-next, and unclamped-next lookup tables. The unclamped next stop models the column a terminal tab would really reach beyond the surface edge; cursor planning depends on that to avoid over-counting forward tab moves near the right margin.

Modules§

cost
Byte-length predictors for renderer ANSI plans.

Structs§

Optimizations
Terminal capabilities the renderer may use for shorter output.