compositor

package
v0.0.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package compositor composes vterm snapshots and UI layers into a single rendered frame. A Canvas holds the working cell grid and is reused across frames; snapshot rendering (RenderSnapshotWithCanvas) and delta-aware ANSI emission keep redraws cheap on the hot render path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderSnapshotWithCanvas added in v0.0.19

func RenderSnapshotWithCanvas(canvas *Canvas, snap *VTermSnapshot, width, height int, fg, bg vterm.Color) string

RenderSnapshotWithCanvas renders a vterm snapshot into a reusable canvas.

Types

type Canvas

type Canvas struct {
	Width  int
	Height int
	Cells  [][]vterm.Cell
	// contains filtered or unexported fields
}

Canvas is a fixed-size buffer of styled cells.

func NewCanvas

func NewCanvas(width, height int) *Canvas

NewCanvas creates a new canvas filled with blank cells.

func (*Canvas) DrawScreen

func (c *Canvas) DrawScreen(x, y, w, h int, screen [][]vterm.Cell, cursor CursorState, viewOffset int, selection SelectionRegion)

DrawScreen draws a vterm screen into the canvas with clipping.

func (*Canvas) Fill

func (c *Canvas) Fill(style vterm.Style)

Fill sets the entire canvas to the given style.

func (*Canvas) Render

func (c *Canvas) Render() string

Render converts the canvas to an ANSI string.

func (*Canvas) Resize

func (c *Canvas) Resize(width, height int)

Resize resets the canvas dimensions when the size changes.

func (*Canvas) SetCell

func (c *Canvas) SetCell(x, y int, cell vterm.Cell)

SetCell sets a cell if within bounds.

type ChromeCache

type ChromeCache struct {
	// contains filtered or unexported fields
}

ChromeCache caches a StringDrawable for static pane chrome. Reuse the cached drawable when layout/content hasn't changed.

func (*ChromeCache) Get

func (c *ChromeCache) Get(content string, width, height int, focused bool, posX, posY int) *StringDrawable

Get returns the cached StringDrawable if the parameters match. Returns nil if cache is invalid and needs rebuild.

func (*ChromeCache) Invalidate

func (c *ChromeCache) Invalidate()

Invalidate clears the cache.

func (*ChromeCache) Set

func (c *ChromeCache) Set(content string, width, height int, focused bool, posX, posY int, drawable *StringDrawable)

Set updates the cache with a new StringDrawable.

type CursorState added in v0.0.14

type CursorState struct {
	X, Y    int
	Visible bool
}

CursorState holds cursor position and visibility for DrawScreen.

type PositionedVTermLayer

type PositionedVTermLayer struct {
	*VTermLayer
	PosX, PosY    int
	Width, Height int
}

func (*PositionedVTermLayer) Draw

func (l *PositionedVTermLayer) Draw(s uv.Screen, r uv.Rectangle)

Draw renders the VTerm snapshot at the specified position within the canvas.

type SelectionRegion added in v0.0.14

type SelectionRegion struct {
	Active         bool
	StartX, StartY int
	EndX, EndY     int
}

SelectionRegion holds selection bounds for DrawScreen.

type SnapshotDoubleBuffer added in v0.0.20

type SnapshotDoubleBuffer struct {
	// contains filtered or unexported fields
}

SnapshotDoubleBuffer alternates between two snapshot buffers so the buffer mutated by an incremental snapshot is never the one most recently handed to a layer. Each buffer carries rows dirtied while the other buffer was the target, because vterm dirty tracking is per snapshot call, not per buffer.

It is not safe for concurrent use; callers must hold the same lock they hold when snapshotting the VTerm.

func (*SnapshotDoubleBuffer) MarkRowStale added in v0.0.20

func (d *SnapshotDoubleBuffer) MarkRowStale(y int)

MarkRowStale records that row y of the most recently handed-out snapshot was mutated in place after creation (e.g. chat cursor sanitization), so the next snapshot into that buffer must re-copy the row even if vterm dirty tracking says it is clean. A nil stale mask already means "fully stale" and needs no marking.

func (*SnapshotDoubleBuffer) Reset added in v0.0.20

func (d *SnapshotDoubleBuffer) Reset()

Reset discards both buffers and all stale-row tracking.

func (*SnapshotDoubleBuffer) Snapshot added in v0.0.20

func (d *SnapshotDoubleBuffer) Snapshot(term *vterm.VTerm, showCursor bool) *VTermSnapshot

Snapshot returns a current terminal snapshot without mutating the snapshot returned by the previous call.

type StringDrawable

type StringDrawable struct {
	// contains filtered or unexported fields
}

StringDrawable wraps a styled ANSI string to implement uv.Drawable. This allows string-based content to be composed onto a lipgloss.Canvas.

func NewStringDrawable

func NewStringDrawable(content string, x, y int) *StringDrawable

NewStringDrawable creates a drawable from a styled string at the given position.

ANSI decoding (SGR styling + grapheme segmentation) happens once here rather than on every Draw call, since content is immutable per instance and drawableCache/borderCache reuse the same *StringDrawable across frames for byte-identical content.

func (*StringDrawable) Draw

func (d *StringDrawable) Draw(screen uv.Screen, r uv.Rectangle)

Draw renders the string onto the screen buffer by blitting the cells parsed once in NewStringDrawable.

type VTermLayer

type VTermLayer struct {
	Snap *VTermSnapshot
}

VTermLayer implements tea.Layer for direct cell-based rendering of a VTerm snapshot. This uses a snapshot to avoid data races - the snapshot is created while holding the VTerm lock, and rendering happens without any locks.

func NewVTermLayer

func NewVTermLayer(snap *VTermSnapshot) *VTermLayer

NewVTermLayer creates a new layer from a VTerm snapshot.

func (*VTermLayer) Draw

func (l *VTermLayer) Draw(s uv.Screen, r uv.Rectangle)

Draw renders the VTerm snapshot directly to the screen buffer. This is the hot path - every optimization here matters.

func (*VTermLayer) DrawAt

func (l *VTermLayer) DrawAt(s uv.Screen, posX, posY, maxWidth, maxHeight int)

DrawAt renders the VTerm snapshot at a specific position with given dimensions. This is the core rendering logic shared by VTermLayer and PositionedVTermLayer.

type VTermSnapshot

type VTermSnapshot struct {
	Screen       [][]vterm.Cell
	DirtyLines   []bool
	AllDirty     bool
	CursorX      int
	CursorY      int
	ViewOffset   int
	CursorHidden bool
	ShowCursor   bool
	// SuppressBlink strips the SGR blink attribute at draw time (chat tabs
	// suppress assistant blink flicker without mutating snapshot rows).
	SuppressBlink bool
	Width         int
	Height        int
	// Selection state (used during rendering)
	SelActive            bool
	SelStartX, SelStartY int
	SelEndX, SelEndY     int
}

func NewVTermSnapshot

func NewVTermSnapshot(term *vterm.VTerm, showCursor bool) *VTermSnapshot

NewVTermSnapshot creates a snapshot from a VTerm. MUST be called while holding the appropriate lock on the VTerm.

func NewVTermSnapshotWithCache

func NewVTermSnapshotWithCache(term *vterm.VTerm, showCursor bool, prev *VTermSnapshot) *VTermSnapshot

NewVTermSnapshotWithCache creates a snapshot from a VTerm, optionally reusing lines from a previous snapshot when dirty line tracking allows. MUST be called while holding the appropriate lock on the VTerm.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL