render

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HideCursor = ansi.HideCursor
	ShowCursor = ansi.ShowCursor
	ClearAll   = ansi.EraseEntireScreen
	Reset      = ansi.ResetStyle

	SynchronizedUpdateBegin = "\x1b[?2026h"
	SynchronizedUpdateEnd   = "\x1b[?2026l"

	MouseEnable  = ansi.SetModeMouseButtonEvent + ansi.SetModeMouseExtSgr
	MouseDisable = ansi.ResetModeMouseExtSgr + ansi.ResetModeMouseButtonEvent

	FocusEnable  = ansi.SetModeFocusEvent
	FocusDisable = ansi.ResetModeFocusEvent

	AltScreenEnter = ansi.SetModeAltScreenSaveCursor
	AltScreenExit  = ansi.ResetModeAltScreenSaveCursor
)
View Source
const GlobalBarHeight = 1

GlobalBarHeight is the number of rows reserved for the global status bar.

Variables

View Source
var (
	Bold   = ansi.SGR(ansi.BoldAttr)
	NoBold = ansi.SGR(ansi.NormalIntensityAttr)

	StrikeOn = ansi.SGR(ansi.StrikethroughAttr)

	DimFg      = foregroundSequence(config.DimColorHex)
	Surface0Bg = backgroundSequence(config.Surface0Hex)
	TextFg     = foregroundSequence(config.TextColorHex)
	GreenFg    = foregroundSequence(config.GreenHex)
	BlueFg     = foregroundSequence(config.BlueHex)
	YellowFg   = foregroundSequence(config.YellowHex)
	RedFg      = foregroundSequence(config.RedHex)

	KittyKeyboardEnable  = ansi.PushKittyKeyboard(1)
	KittyKeyboardDisable = ansi.DisableKittyKeyboard

	ResetTitle = ansi.SetIconNameWindowTitle("")
)

Functions

func CSIParams

func CSIParams(s string, i int) (string, byte, int)

CSIParams returns the parameter string and final byte of a CSI sequence starting at s[i] (which must be the byte after '['). On success it returns (params, finalByte, endIndex) where endIndex is one past the final byte. Truncated sequences preserve any parameters collected before parsing stopped.

func Clamp

func Clamp(v, lo, hi int) int

Clamp restricts v to the range [lo, hi].

func EmitDiff

func EmitDiff(changes []CellChange) string

EmitDiff produces minimal ANSI output for the given cell changes. Changes must be in row-major order (as returned by DiffGrid). Consecutive cells on the same row share a single CUP escape. Does not emit HideCursor/ShowCursor — the compositor handles those.

func ExtractColorMap

func ExtractColorMap(ansiStream string, width, height int) string

ExtractColorMap takes a raw ANSI capture stream and produces a human-readable color map. At each border character position, the active ANSI foreground color is mapped to a letter (Catppuccin name initial) or '.' for dim. Non-border positions are spaces.

func GlobalBarHelpToggleAtColumn added in v0.3.0

func GlobalBarHelpToggleAtColumn(x, width, paneCount int, showHelp bool, now time.Time) bool

GlobalBarHelpToggleAtColumn reports whether x hits the clickable "? help" region in the global status bar.

func GlobalBarShowsHelp added in v0.3.0

func GlobalBarShowsHelp(width int, sessionName string, paneCount int, windows []WindowInfo, message string, now time.Time) bool

GlobalBarShowsHelp reports whether the current terminal width can render the clickable "? help" segment without colliding with the right-side status text.

func MaterializeGrid

func MaterializeGrid(ansiStream string, width, height int) string

MaterializeGrid replays an ANSI escape stream onto a 2D character grid and returns the result as newline-separated rows. Only CUP (\033[row;colH) cursor positioning is handled; other cursor movement (A/B/C/D) is skipped. This is sufficient for the compositor's output, which uses CUP exclusively.

func ParseCUP

func ParseCUP(params string) (row, col int)

ParseCUP parses CSI CUP parameters "row;col" (1-based). Missing values default to 1.

func RenderPaneViewportANSI

func RenderPaneViewportANSI(width, height int, active bool, pd PaneData) string

Types

type CellChange

type CellChange struct {
	X, Y int
	Cell ScreenCell
}

CellChange records a single cell that differs between two grids.

func DiffGrid

func DiffGrid(prev, next *ScreenGrid) []CellChange

DiffGrid compares prev and next and returns changed cells in row-major order. If prev is nil, every cell in next is returned (initial full paint).

type ChooserOverlay

type ChooserOverlay struct {
	Title    string
	Query    string
	Rows     []ChooserOverlayRow
	Selected int
}

ChooserOverlay is a client-local modal chooser rendered above the layout.

type ChooserOverlayRow

type ChooserOverlayRow struct {
	Text       string
	Selectable bool
}

ChooserOverlayRow is one rendered row in the chooser modal.

type Compositor

type Compositor struct {
	TimeNow func() time.Time // returns current time; nil defaults to time.Now
	// contains filtered or unexported fields
}

Compositor composes pane content into terminal output.

func NewCompositor

func NewCompositor(width, height int, sessionName string) *Compositor

NewCompositor creates a compositor for the given terminal dimensions.

func (*Compositor) ClearPrevGrid

func (c *Compositor) ClearPrevGrid()

ClearPrevGrid forces a full repaint on the next RenderDiff call.

func (*Compositor) ColorProfile added in v0.2.0

func (c *Compositor) ColorProfile() termenv.Profile

ColorProfile reports the compositor's current terminal color profile.

func (*Compositor) LayoutHeight

func (c *Compositor) LayoutHeight() int

LayoutHeight returns the height available for the layout tree (terminal height minus the global status bar).

func (*Compositor) PrevGridText

func (c *Compositor) PrevGridText() string

PrevGridText returns the previous frame's grid as plain text (no ANSI). Each row is newline-separated; trailing spaces are trimmed. Returns empty string if no previous grid exists (before first render).

func (*Compositor) RenderDiffWithOverlay

func (c *Compositor) RenderDiffWithOverlay(root *mux.LayoutCell, activePaneID uint32, lookup func(uint32) PaneData, overlay OverlayState) string

RenderDiffWithOverlay composes all panes into a cell grid, diffs against the previous frame, and returns minimal ANSI output for the changed cells plus optional client-local overlays. On the first call (or after Resize), prevGrid is nil and every cell is emitted.

func (*Compositor) RenderDiffWithOverlayDirty added in v0.3.0

func (c *Compositor) RenderDiffWithOverlayDirty(
	root *mux.LayoutCell,
	activePaneID uint32,
	lookup func(uint32) PaneData,
	overlay OverlayState,
	dirtyPanes map[uint32]struct{},
	fullRedraw bool,
) string

RenderDiffWithOverlayDirty composes all panes into a cell grid, reusing cached cells for clean panes when possible, diffs against the previous frame, and returns minimal ANSI output for the changed cells.

func (*Compositor) RenderDiffWithOverlayDirtyStats added in v0.3.0

func (c *Compositor) RenderDiffWithOverlayDirtyStats(
	root *mux.LayoutCell,
	activePaneID uint32,
	lookup func(uint32) PaneData,
	overlay OverlayState,
	dirtyPanes map[uint32]struct{},
	fullRedraw bool,
) (string, RenderStats)

func (*Compositor) RenderFullWithOverlay

func (c *Compositor) RenderFullWithOverlay(root *mux.LayoutCell, activePaneID uint32, lookup func(uint32) PaneData, overlay OverlayState, clearScreen ...bool) string

RenderFullWithOverlay composes all panes, status lines, and borders into ANSI output plus optional client-local overlays. lookup maps pane IDs to their rendering data. Client provides emulator-backed adapters; server could provide Pane wrappers.

When clearScreen is true the entire terminal is erased before drawing. This is required after layout changes (panes move/resize) but should be skipped for incremental updates (pane output, copy mode navigation) to avoid flicker.

func (*Compositor) RenderFullWithOverlayStats added in v0.3.0

func (c *Compositor) RenderFullWithOverlayStats(root *mux.LayoutCell, activePaneID uint32, lookup func(uint32) PaneData, overlay OverlayState, clearScreen ...bool) (string, RenderStats)

func (*Compositor) Resize

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

Resize updates the compositor's terminal dimensions.

func (*Compositor) SetColorProfile added in v0.2.0

func (c *Compositor) SetColorProfile(profile termenv.Profile)

SetColorProfile updates the terminal color profile used for ANSI rendering.

func (*Compositor) SetSessionName

func (c *Compositor) SetSessionName(name string)

SetSessionName updates the session name shown in the global bar.

func (*Compositor) SetWindows

func (c *Compositor) SetWindows(windows []WindowInfo)

SetWindows sets the window list for the global bar.

type DropIndicatorOverlay added in v0.2.0

type DropIndicatorOverlay struct {
	X, Y int
	W, H int
}

DropIndicatorOverlay draws a temporary gray placeholder rectangle while a pane is being dragged to a new drop target.

type GlobalBarWindowDropTarget added in v0.4.0

type GlobalBarWindowDropTarget struct {
	DestinationIndex int
	IndicatorColumn  int
}

GlobalBarWindowDropTarget describes a tab reorder destination resolved from a hovered global-bar tab.

func GlobalBarWindowDropTargetAtColumn added in v0.4.0

func GlobalBarWindowDropTargetAtColumn(windows []WindowInfo, sourceIndex, x int) (GlobalBarWindowDropTarget, bool)

GlobalBarWindowDropTargetAtColumn resolves a hovered tab to a destination index and insertion-marker column for drag-reordering window tabs.

type HelpBarOverlay added in v0.3.0

type HelpBarOverlay struct {
	Rows []string
}

HelpBarOverlay is a client-local multi-row help footer rendered above the global session bar.

type OOBWrite

type OOBWrite struct {
	X, Y int
}

OOBWrite records a single out-of-bounds Set() call.

type OverlayState

type OverlayState struct {
	PaneLabels          []PaneOverlayLabel
	DropIndicator       *DropIndicatorOverlay
	WindowDropIndicator *WindowDropIndicatorOverlay
	Chooser             *ChooserOverlay
	TextInput           *TextInputOverlay
	Message             string
	HelpBar             *HelpBarOverlay
	PressedPaneID       uint32
}

OverlayState captures optional client-local overlays that sit on top of the normal pane layout rendering.

func (OverlayState) IsPanePressed added in v0.3.0

func (o OverlayState) IsPanePressed(paneID uint32) bool

IsPanePressed reports whether the pane with the given ID is currently in a pressed/drag state.

type PaneData

type PaneData interface {
	// RenderScreen returns the pane's screen content as an ANSI string.
	// When active is false, app-rendered cursor blocks (isolated reverse-video
	// spaces) are stripped so unfocused panes don't show stray cursors.
	RenderScreen(active bool) string
	// CellAt returns the cell at (col, row) for cell-grid compositing.
	// For inactive panes, cursor block reverse-video is cleared.
	CellAt(col, row int, active bool) ScreenCell
	// CopyModeOverlay returns the current copy-mode overlay state for the pane,
	// or nil when the pane is not in copy mode.
	CopyModeOverlay() *proto.ViewportOverlay
	CursorPos() (col, row int)
	CursorHidden() bool
	// HasCursorBlock reports whether the screen contains an app-rendered
	// block cursor (isolated reverse-video space). When true, the compositor
	// hides the terminal cursor to avoid showing two cursors.
	HasCursorBlock() bool
	ID() uint32
	Name() string
	TrackedPRs() []proto.TrackedPR
	TrackedIssues() []proto.TrackedIssue
	Issue() string
	Host() string
	Task() string
	Color() string
	Idle() bool
	IsLead() bool
	// ConnStatus returns the connection state for remote panes:
	// "", "connected", "reconnecting", or "disconnected".
	ConnStatus() string
	InCopyMode() bool
	// CopyModeSearch returns the search prompt text (e.g., "/pattern")
	// when the user is actively typing a search in copy mode. Empty otherwise.
	CopyModeSearch() string
}

PaneData provides the data the compositor needs for rendering a pane. Server-side *mux.Pane and client-side emulator+metadata adapters both satisfy this interface.

type PaneOverlayLabel

type PaneOverlayLabel struct {
	PaneID uint32
	Label  string
}

PaneOverlayLabel identifies a temporary overlay label for a pane.

type RenderStats added in v0.3.0

type RenderStats struct {
	CellsDiffed     int
	PanesComposited int
}

RenderStats captures lightweight render counters alongside ANSI output.

type ScreenCell

type ScreenCell struct {
	Char  string   // grapheme cluster ("" treated as space)
	Link  uv.Link  // OSC-8 hyperlink state for this cell
	Style uv.Style // foreground, background, attributes
	Width int      // 1=normal, 2=wide, 0=continuation
}

ScreenCell represents a single cell in the composited screen grid.

func CellFromUV

func CellFromUV(c *uv.Cell) ScreenCell

CellFromUV converts a VT library cell to a ScreenCell.

func ScreenCellFromCopyMode

func ScreenCellFromCopyMode(cell proto.Cell) ScreenCell

func (ScreenCell) Equal

func (c ScreenCell) Equal(o ScreenCell) bool

Equal reports whether two cells are visually identical.

type ScreenGrid

type ScreenGrid struct {
	Width, Height int
	Cells         []ScreenCell // Cells[y*Width + x]
	Debug         bool         // when true, OOB Set() calls are recorded for inspection in tests
	// contains filtered or unexported fields
}

ScreenGrid is a 2D grid of screen cells in row-major order.

func NewScreenGrid

func NewScreenGrid(width, height int) *ScreenGrid

NewScreenGrid creates a grid filled with space cells.

func (*ScreenGrid) Clone added in v0.3.0

func (g *ScreenGrid) Clone() *ScreenGrid

Clone returns a deep copy of the grid cell contents.

func (*ScreenGrid) Get

func (g *ScreenGrid) Get(x, y int) ScreenCell

Get reads the cell at (x, y). Out-of-bounds returns a space cell.

func (*ScreenGrid) Set

func (g *ScreenGrid) Set(x, y int, cell ScreenCell)

Set writes a cell at (x, y). Out-of-bounds writes are silently ignored. When Debug is true, OOB writes are also recorded for later inspection.

type TextInputOverlay

type TextInputOverlay struct {
	Title string
	Input string
}

TextInputOverlay is a client-local modal prompt rendered above the layout.

type WindowDropIndicatorOverlay added in v0.4.0

type WindowDropIndicatorOverlay struct {
	Column int
}

WindowDropIndicatorOverlay draws a temporary insertion marker in the global status bar while a window tab is being dragged.

type WindowInfo

type WindowInfo struct {
	Index    int
	Name     string
	IsActive bool
	Panes    int
}

WindowInfo holds metadata about a window for rendering in the global bar.

func GlobalBarWindowAtColumn

func GlobalBarWindowAtColumn(windows []WindowInfo, x int) (WindowInfo, bool)

GlobalBarWindowAtColumn resolves a 0-based terminal column within the rendered global bar to the corresponding window tab.

Jump to

Keyboard shortcuts

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