render

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ZBase is for base content:
	// revisions list, diff view, oplog, details, describe, bookmark operations
	ZBase = 0

	// ZFuzzyInput is for fuzzy input fields, text inputs, and revset list items
	ZFuzzyInput = 1

	// ZPreview is for preview panels and split views
	ZPreview = 10

	// ZFuzzyOverlay is for floating fuzzy overlays that should appear above preview
	ZFuzzyOverlay = 12

	// ZRevsetOverlay is for revset overlay content (above preview)
	ZRevsetOverlay = 15

	// ZDialogs is for dialogs (undo/redo confirmation, input fields)
	// that should appear above the preview panel
	ZDialogs = 50

	// ZMenuBorder is for menu borders (git, bookmarks, choose, custom_commands)
	ZMenuBorder = 100

	// ZMenuContent is for menu content items
	ZMenuContent = 101

	// ZOverlay is for overlays like sequence overlay and flash messages
	ZOverlay = 200

	// ZExpandedStatus is for the expanded status bar help overlay (highest UI overlay)
	ZExpandedStatus = 275

	// ZPassword is for password input (highest priority modal)
	ZPassword = 300
)

Z-index constants for layered rendering. Higher values render on top. Components should use these named constants instead of magic numbers.

Variables

This section is empty.

Functions

func BlockWidth added in v0.10.2

func BlockWidth(s string) int

BlockWidth returns the display width of the widest line in a multiline string.

func ClampStartLine

func ClampStartLine(startLine, viewHeight, totalLines int) int

ClampStartLine constrains a scroll start line to valid bounds. totalLines is the sum of all item heights; viewHeight is the visible area height.

func ExpandTabs added in v0.10.3

func ExpandTabs(line string) string

ExpandTabs converts tabs to spaces while preserving ANSI escape sequences in the visible text. Callers should pass a single line so tab stops reset at newline boundaries.

func NewScreenBuffer added in v0.10.2

func NewScreenBuffer(w, h int) uv.ScreenBuffer

NewScreenBuffer creates a screen buffer using the current width method.

func SetWidthMethod added in v0.10.2

func SetWidthMethod(m ansi.Method)

SetWidthMethod updates the render width method.

func StringWidth added in v0.10.2

func StringWidth(s string) int

StringWidth returns the display width of a string.

func WidthMethod added in v0.10.2

func WidthMethod() ansi.Method

WidthMethod returns the current render width method.

Types

type ClickMessage

type ClickMessage = tea.Msg

type ClickMessageFunc

type ClickMessageFunc func(index int, mouse tea.Mouse) ClickMessage

type DimEffect

type DimEffect struct {
	Rect layout.Rectangle
	Z    int
}

DimEffect dims the content by setting the Faint attribute.

func (DimEffect) Apply

func (e DimEffect) Apply(buf uv.Screen)

func (DimEffect) GetRect

func (e DimEffect) GetRect() layout.Rectangle

func (DimEffect) GetZ

func (e DimEffect) GetZ() int

type DisplayContext

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

DisplayContext holds all rendering operations for a frame. Operations are accumulated during the layout/render pass, then executed in order by batch and Z-index.

func NewDisplayContext

func NewDisplayContext() *DisplayContext

NewDisplayContext creates a new empty display context.

func (*DisplayContext) AddBackdrop added in v0.10.0

func (dl *DisplayContext) AddBackdrop(rect layout.Rectangle, z int)

AddBackdrop swallows click/scroll input in a region.

func (*DisplayContext) AddDim

func (dl *DisplayContext) AddDim(rect layout.Rectangle, z int)

AddDim adds a DimEffect (dims the content).

func (*DisplayContext) AddDraw

func (dl *DisplayContext) AddDraw(rect layout.Rectangle, content string, z int)

AddDraw adds a Draw to the display context.

func (*DisplayContext) AddEffect

func (dl *DisplayContext) AddEffect(effect Effect)

AddEffect adds a custom Effect to the display context. This is the generic method that accepts any Effect implementation.

func (*DisplayContext) AddFill

func (dl *DisplayContext) AddFill(rect layout.Rectangle, ch rune, style lipgloss.Style, z int)

AddFill fills a rectangle with the provided rune and style.

func (*DisplayContext) AddHighlight

func (dl *DisplayContext) AddHighlight(rect layout.Rectangle, style lipgloss.Style, z int)

AddHighlight adds a HighlightEffect.

func (*DisplayContext) AddInteraction

func (dl *DisplayContext) AddInteraction(rect layout.Rectangle, msg tea.Msg, typ InteractionType, z int)

AddInteraction adds an InteractionOp to the display context.

func (*DisplayContext) AddInteractionFn added in v0.10.0

func (dl *DisplayContext) AddInteractionFn(rect layout.Rectangle, fn func(tea.MouseMsg) tea.Msg, typ InteractionType, z int)

AddInteractionFn adds an interaction whose message is computed from the mouse event.

func (*DisplayContext) AddPaint

func (dl *DisplayContext) AddPaint(rect layout.Rectangle, style lipgloss.Style, z int)

AddPaint adds a HighlightEffect with Force enabled, overriding existing background colors.

func (*DisplayContext) ProcessMouseEvent

func (dl *DisplayContext) ProcessMouseEvent(msg tea.MouseMsg) (tea.Msg, bool)

ProcessMouseEvent routes a mouse event through the registered interactions.

func (*DisplayContext) Render

func (dl *DisplayContext) Render(buf uv.Screen)

Render executes all operations in the display context to the given screen. Order of execution: 1. Draw sorted by Z-index (low to high) 2. Effects sorted by Z-index (low to high)

func (*DisplayContext) RenderToString

func (dl *DisplayContext) RenderToString(width, height int) string

RenderToString is a convenience method that renders to a new buffer and returns the final string output.

func (*DisplayContext) Text

func (dl *DisplayContext) Text(x, y, z int) *TextBuilder

type DragStartCarrier

type DragStartCarrier interface {
	SetDragStart(x, y int) tea.Msg
}

DragStartCarrier is an interface for messages that carry drag start coordinates. The ProcessMouseEvent function will set the drag start position for drag interactions.

type Draw

type Draw struct {
	Rect    layout.Rectangle // The area to draw in
	Content string           // Rendered ANSI string (from lipgloss, etc.)
	Z       int              // Z-index for layering (lower = back, higher = front)
}

Draw represents a content rendering operation. DrawOps are rendered first, sorted by Z-index (lower values render first).

type Effect

type Effect interface {
	// Apply applies the effect to the buffer
	Apply(buf uv.Screen)
	// GetZ returns the Z-index for layering (higher Z renders later)
	GetZ() int
	// GetRect returns the rectangle this effect applies to
	GetRect() layout.Rectangle
}

Effect is the interface that all effect operations must implement. Effects are post-processing operations that modify already-rendered content.

type FillEffect

type FillEffect struct {
	Rect  layout.Rectangle
	Char  rune
	Style uv.Style
	Z     int
}

func (FillEffect) Apply

func (e FillEffect) Apply(buf uv.Screen)

func (FillEffect) GetRect

func (e FillEffect) GetRect() layout.Rectangle

func (FillEffect) GetZ

func (e FillEffect) GetZ() int

type HighlightEffect

type HighlightEffect struct {
	Rect  layout.Rectangle
	Style lipgloss.Style
	Z     int
	Force bool
}

HighlightEffect applies a highlight style by changing the background color. Extracts the background color from the lipgloss.Style and applies it to cells.

func (HighlightEffect) Apply

func (e HighlightEffect) Apply(buf uv.Screen)

func (HighlightEffect) GetRect

func (e HighlightEffect) GetRect() layout.Rectangle

func (HighlightEffect) GetZ

func (e HighlightEffect) GetZ() int

type InteractionOp

type InteractionOp struct {
	Rect  layout.Rectangle           // The interactive area (absolute coordinates)
	Msg   tea.Msg                    // Message to send (static)
	MsgFn func(tea.MouseMsg) tea.Msg // Optional message factory.
	Type  InteractionType            // What kind of interaction this supports
	Z     int                        // Z-index for overlapping regions (higher = priority)
}

InteractionOp represents an interactive region that responds to input.

type InteractionType

type InteractionType int

InteractionType defines what kinds of input an interactive region responds to. Multiple types can be combined using bitwise OR.

const (
	InteractionClick InteractionType = 1 << iota
	InteractionScroll
	InteractionDrag
)

type ListRenderer

type ListRenderer struct {
	StartLine     int
	ScrollMsg     tea.Msg
	Z             int // Interaction z-index; default is 0.
	FirstRowIndex int
	LastRowIndex  int
}

func NewListRenderer

func NewListRenderer(scrollMsg tea.Msg) *ListRenderer

func (*ListRenderer) GetFirstRowIndex

func (r *ListRenderer) GetFirstRowIndex() int

func (*ListRenderer) GetLastRowIndex

func (r *ListRenderer) GetLastRowIndex() int

func (*ListRenderer) GetScrollOffset

func (r *ListRenderer) GetScrollOffset() int

func (*ListRenderer) RegisterScroll

func (r *ListRenderer) RegisterScroll(dl *DisplayContext, viewRect layout.Box)

RegisterScroll registers a scroll interaction for the given view rect. Call this after Render if you want to enable mouse wheel scrolling.

func (*ListRenderer) Render

func (r *ListRenderer) Render(
	dl *DisplayContext,
	viewRect layout.Box,
	itemCount int,
	cursor int,
	ensureCursorVisible bool,
	measure measureItemFunc,
	render RenderItemFunc,
	clickMsg ClickMessageFunc,
)

Render renders visible items to the DisplayContext. Note: Scroll interaction registration is the caller's responsibility.

func (*ListRenderer) SetScrollOffset

func (r *ListRenderer) SetScrollOffset(offset int)

type RenderItemFunc

type RenderItemFunc func(dl *DisplayContext, index int, rect layout.Rectangle)

type ScrollDeltaCarrier

type ScrollDeltaCarrier interface {
	SetDelta(delta int, horizontal bool) tea.Msg
}

ScrollDeltaCarrier is an interface for messages that carry scroll delta information. The ProcessMouseEvent function will set the Delta field for scroll interactions.

type TextBuilder

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

func (*TextBuilder) Clickable

func (tb *TextBuilder) Clickable(text string, style lipgloss.Style, onClick tea.Msg) *TextBuilder

func (*TextBuilder) Done

func (tb *TextBuilder) Done()

func (*TextBuilder) Measure

func (tb *TextBuilder) Measure() (int, int)

func (*TextBuilder) NewLine

func (tb *TextBuilder) NewLine() *TextBuilder

func (*TextBuilder) Space

func (tb *TextBuilder) Space(count int) *TextBuilder

func (*TextBuilder) Styled

func (tb *TextBuilder) Styled(text string, style lipgloss.Style) *TextBuilder

func (*TextBuilder) Write

func (tb *TextBuilder) Write(text string) *TextBuilder

Jump to

Keyboard shortcuts

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