layout

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinWidth    = 40
	CompactMax  = 59
	StandardMax = 79
)

Width thresholds.

View Source
const ChromeHeight = 2

ChromeHeight is the total number of rows consumed by the unified header and footer. Content height = terminal height - ChromeHeight.

Variables

This section is empty.

Functions

func BuildFooter

func BuildFooter(info FooterInfo, width int, bp Breakpoint, t theme.Theme, cache *theme.StyleCache) string

BuildFooter renders the unified 1-line footer bar.

Layout (premium): ⌂ cwd ⎇ branch │ ⠹ responding... │ ctrl+p · ctrl+b $0.02 Uses │ separators to create distinct zones with visual weight.

func BuildHeader

func BuildHeader(info HeaderInfo, width int, bp Breakpoint, t theme.Theme, cache *theme.StyleCache) string

BuildHeader renders the unified 1-line header bar.

Layout (premium): M31A │ breadcrumb ········ model [provider] [ctx] Uses │ separators and leader dots to create visual depth.

func CenterText

func CenterText(text string, style lipgloss.Style, width int) string

CenterText centers a styled text within a given width.

func FitContent added in v1.2.0

func FitContent(content string, w, h int) string

FitContent ensures content fits within exactly w columns and h rows, padding with spaces or clipping as needed.

func RenderBox added in v1.2.0

func RenderBox(content string, w, h int, opts ...BoxOption) string

RenderBox is a convenience function that creates a Box, solves it, and returns the rendered string. It handles the common case of a single bordered, padded container.

func RenderCard added in v1.2.0

func RenderCard(title, content string, w int, border lipgloss.Border, borderColor, bg lipgloss.Color) string

RenderCard renders a card-style box with title, content, border, and padding.

func RenderDimmed added in v1.2.0

func RenderDimmed(content string, t theme.Theme) string

RenderDimmed applies a dimming effect to content by prepending the ANSI faint attribute to each line, preserving existing styling.

func RenderDimmedOverlay added in v1.2.0

func RenderDimmedOverlay(base string, overlay string, width, height int, t theme.Theme) string

RenderDimmedOverlay composites a dimmed base with a centered overlay.

func RenderModalOverlay added in v1.2.0

func RenderModalOverlay(base string, modal string, width, height int, t theme.Theme) string

RenderModalOverlay renders a modal centered on a dimmed background. Uses string-based line composition (left + modal + right segments joined by concatenation) to avoid corrupting ANSI escape codes that rune-by-rune stamping would break.

func RenderOverlay

func RenderOverlay(base string, overlay string, width, height, overlayWidth int, t theme.Theme) string

RenderOverlay renders a sidebar or modal overlay on top of existing content. The overlay occupies the right portion of the terminal with a dimmed backdrop.

func RenderPage

func RenderPage(chrome PageChrome, content string, header HeaderInfo, footer FooterInfo, t theme.Theme, cache *theme.StyleCache) string

RenderPage composes the unified page layout: 1-line header + content + 1-line footer. The total output is exactly Height rows.

func RenderStack added in v1.2.0

func RenderStack(width, height int, layers []StackLayer) string

RenderStack composites multiple layers at different Z-depths. Later layers render on top of earlier ones. The base layer is filled with spaces.

func RenderTooNarrow

func RenderTooNarrow(width, height int, t theme.Theme) string

RenderTooNarrow renders a centered "resize terminal" message when the terminal is below the minimum width threshold.

func ShowFooterCost

func ShowFooterCost(width int) bool

ShowFooterCost returns true when token/cost info should appear in the footer. Hidden below 80 cols.

func ShowFooterHints

func ShowFooterHints(width int) bool

ShowFooterHints returns true when keyboard shortcut hints should appear in the footer. Hidden below 60 cols.

func ShowHeaderRight

func ShowHeaderRight(width int) bool

ShowHeaderRight returns true when the header right zone (model badge, context meter) should be rendered. Hidden below 60 cols.

func ShowSidebar

func ShowSidebar(width int) bool

ShowSidebar returns true when the sidebar should be displayed alongside content (width ≥ 80). Below this threshold the sidebar is hidden and can only be shown as an overlay via ctrl+b.

func Solve added in v1.2.0

func Solve(root *Box) string

Solve recursively resolves the layout tree and returns the rendered string. The root Box's Width and Height define the available space. If 0, content sizes itself.

func SplitHorizontal added in v1.2.0

func SplitHorizontal(totalW int, count int, gap int, fixed ...int) []int

SplitHorizontal splits available width among N children with optional gaps. Returns a slice of widths. Fixed widths are honored first, then remaining space is divided equally.

func SplitVertical added in v1.2.0

func SplitVertical(totalH int, count int, gap int, fixed ...int) []int

SplitVertical splits available height among N children with optional gaps.

Types

type Align added in v1.2.0

type Align int

Align controls alignment of children within a Box.

const (
	AlignStart Align = iota
	AlignCenter
	AlignEnd
)

type Box added in v1.2.0

type Box struct {
	// Fixed dimensions. 0 means auto (fill available space).
	Width  int
	Height int

	// Flex grow factor. Children with Flex > 0 share remaining space
	// proportionally after fixed-size children are allocated.
	Flex int

	// Direction of child layout.
	Direction FlexDirection

	// Cross-axis alignment of children.
	Align Align

	// Gap between children in cells.
	Gap int

	// Inner padding.
	Padding Insets

	// Border style.
	Border lipgloss.Border

	// Border color.
	BorderColor lipgloss.Color

	// Background color.
	Background lipgloss.Color

	// Content is rendered when there are no children.
	Content Renderer

	// Children are laid out according to Direction and Flex.
	Children []*Box
}

Box is the fundamental layout primitive. It arranges children either in a Row or Column, distributing space using flex factors.

func NewColumn added in v1.2.0

func NewColumn(children ...*Box) *Box

NewColumn creates a column-direction Box.

func NewRow added in v1.2.0

func NewRow(children ...*Box) *Box

NewRow creates a row-direction Box.

func (*Box) WithBackground added in v1.2.0

func (b *Box) WithBackground(bg lipgloss.Color) *Box

WithBackground sets the background color and returns the Box.

func (*Box) WithBorder added in v1.2.0

func (b *Box) WithBorder(border lipgloss.Border, color lipgloss.Color) *Box

WithBorder sets border and color and returns the Box.

func (*Box) WithContent added in v1.2.0

func (b *Box) WithContent(r Renderer) *Box

WithContent sets the content renderer and returns the Box.

func (*Box) WithFlex added in v1.2.0

func (b *Box) WithFlex(f int) *Box

WithFlex sets the flex grow factor and returns the Box.

func (*Box) WithPadding added in v1.2.0

func (b *Box) WithPadding(p int) *Box

WithPadding sets uniform padding and returns the Box.

func (*Box) WithSize added in v1.2.0

func (b *Box) WithSize(w, h int) *Box

WithSize sets fixed width and height and returns the Box.

type BoxOption added in v1.2.0

type BoxOption func(*Box)

BoxOption configures a Box for RenderBox.

func WithBoxBackground added in v1.2.0

func WithBoxBackground(bg lipgloss.Color) BoxOption

WithBoxBackground sets the background color.

func WithBoxBorder added in v1.2.0

func WithBoxBorder(border lipgloss.Border, color lipgloss.Color) BoxOption

WithBoxBorder sets a border on the Box.

func WithBoxPadding added in v1.2.0

func WithBoxPadding(p int) BoxOption

WithBoxPadding sets uniform padding.

type Breakpoint

type Breakpoint int

Breakpoint classifies terminal width for responsive layout decisions.

const (
	// UltraNarrow: < 40 cols — show "resize terminal" message only.
	UltraNarrow Breakpoint = iota
	// Compact: 40–59 cols — minimal chrome, no sidebar, no hints.
	Compact
	// Standard: 60–79 cols — full chrome, no sidebar.
	Standard
	// Full: ≥ 80 cols — sidebar visible, all chrome, full key hints.
	Full
)

func Detect

func Detect(width int) Breakpoint

Detect returns the breakpoint for a given terminal width.

type FlexDirection added in v1.2.0

type FlexDirection int

FlexDirection controls child arrangement within a Box.

const (
	Column FlexDirection = iota
	Row
)

type FooterInfo

type FooterInfo struct {
	Cwd           string   // working directory basename
	GitBranch     string   // current git branch
	Operation     string   // "thinking...", "responding...", phase name
	LeaderActive  bool     // leader key mode active
	KeyboardHints []string // e.g. "ctrl+p commands"
	TokenCount    int      // total tokens used
	Cost          float64  // session cost
	ShowCost      bool     // whether to display cost
	SpinnerFrame  string   // animated spinner character
}

FooterInfo carries the data needed to render the unified footer.

type HeaderInfo

type HeaderInfo struct {
	Brand      string // "M31A"
	Breadcrumb string // screen name, phase breadcrumb, or git branch
	ModelName  string // active model name
	Provider   string // provider short name (OR, ZEN)
	CtxUsed    int    // context tokens used
	CtxTotal   int    // context tokens total
	CtxHistory []int  // recent context usage readings for sparkline
}

HeaderInfo carries the data needed to render the unified header.

type Insets added in v1.2.0

type Insets struct {
	Top    int
	Right  int
	Bottom int
	Left   int
}

Insets represents padding or margin on four sides.

func SymmetricInsets added in v1.2.0

func SymmetricInsets(vertical, horizontal int) Insets

SymmetricInsets creates insets with equal vertical and horizontal values.

func UniformInsets added in v1.2.0

func UniformInsets(v int) Insets

UniformInsets creates insets with equal values on all sides.

func (Insets) Horizontal added in v1.2.0

func (i Insets) Horizontal() int

Horizontal returns the sum of Left + Right.

func (Insets) Vertical added in v1.2.0

func (i Insets) Vertical() int

Vertical returns the sum of Top + Bottom.

type PageChrome

type PageChrome struct {
	Width  int
	Height int
}

PageChrome holds the computed header and footer strings along with dimensions used for content layout.

func (PageChrome) ContentHeight

func (p PageChrome) ContentHeight() int

ContentHeight returns the number of rows available for screen content.

func (PageChrome) ContentWidth

func (p PageChrome) ContentWidth() int

ContentWidth returns the width available for screen content.

type RenderFunc added in v1.2.0

type RenderFunc func(width, height int) string

RenderFunc adapts a function to the Renderer interface.

func (RenderFunc) Render added in v1.2.0

func (f RenderFunc) Render(width, height int) string

type Renderer added in v1.2.0

type Renderer interface {
	Render(width, height int) string
}

Renderer is anything that can render to a string given constraints.

type StackLayer added in v1.2.0

type StackLayer struct {
	Content string
	X       int // horizontal offset from left
	Y       int // vertical offset from top
	Width   int // 0 = auto from content
	Height  int // 0 = auto from content
}

StackLayer represents one layer in a Z-order composition.

type StaticRenderer added in v1.2.0

type StaticRenderer struct {
	Content string
}

StaticRenderer wraps a pre-rendered string as a Renderer.

func (StaticRenderer) Render added in v1.2.0

func (s StaticRenderer) Render(_, _ int) string

Jump to

Keyboard shortcuts

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