layout

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 14 Imported by: 4 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package layout provides frame-based structural layout primitives for terminal UIs built with viewkit.

Index

Examples

Constants

View Source
const (
	DefaultFlexMinWidth = 40
	DefaultFlexMaxCols  = 4
)

Defaults for FlexColumns/FlexRows/FlexSections when MinWidth or MaxCols is unset (< 1): tracks at least 40 cells wide, at most 4 of them.

View Source
const DialogMaxWidth = 56

DialogMaxWidth caps how wide DialogWidth will grow on a wide screen.

View Source
const MinTrackWidth = SlimMinWidth

MinTrackWidth is the narrowest column a tiling layout will create. It is the same floor Slim panes use, and it is what Frame.CellBox needs to stay inside the rect its layout hands it. It is not enough for Frame.TitledBox, which clamps its body up to theme.MinBodyWidth and therefore needs theme.MinBodyWidth+4 columns; panes that tile into narrow tracks want Frame.CellTitledBox, which clamps down instead.

View Source
const SlimMinWidth = 20

SlimMinWidth is the narrowest a Slim pane will be squeezed to (in cells) before it stops shrinking.

Variables

View Source
var (
	ErrUnknownLayout = errors.New("layout: unknown layout")
	ErrUnknownPane   = errors.New("layout: unknown pane")
)

ErrUnknownLayout and ErrUnknownPane report spec keys missing from the registry; match with errors.Is.

View Source
var Center = OverlayPos{XFrac: 0.5, YFrac: 0.5}

Center anchors an overlay in the middle of the background.

View Source
var StrictScope bool

StrictScope is a test hook — when true, Frame accessors panic on nil UI so fallback leaks surface.

Functions

func BodyBudget

func BodyBudget(height int) int

BodyBudget converts a terminal height into the rows available to the body after the vertical app margins, floored at 1. A non-positive height (size unknown) assumes the minimum body height rather than returning 0.

func ContentRows

func ContentRows(height int) int

ContentRows is BodyBudget for callers that would rather render nothing than guess: a non-positive height returns 0 instead of the minimum-height fallback.

func CountLines

func CountLines(s string) int

CountLines reports how many display lines s occupies. Unlike strings.Count+1 conventions elsewhere, an empty string still counts as one line, and a trailing newline adds a final (empty) line.

func DialogWidth added in v0.1.6

func DialogWidth(screenWidth int) int

DialogWidth returns the width for a modal drawn over a screen of the given width: inset from both edges, but never wider than DialogMaxWidth.

func FillHeight added in v0.0.4

func FillHeight(body string, height int) string

FillHeight pads body with trailing newlines until it spans height rows. A body already at or over the height is returned unchanged — nothing is trimmed.

func FirstLine added in v0.1.6

func FirstLine(s string) string

FirstLine returns the first non-empty line of s with surrounding whitespace trimmed, or "" when s holds no text. It measures nothing — pair it with Fit when the result also needs to respect a width budget.

func Fit

func Fit(s string, width int) string

Fit truncates a single line to width cells, ANSI-aware, appending an ellipsis when it cuts. Unlike Spread it only ever shortens one string; widths below 1 return "".

func FitBlock

func FitBlock(block string, w, h int) string

FitBlock forces block to exactly w x h cells: each line is ANSI-aware truncated or space-padded to w, and rows are dropped or blank-padded to h.

func FitCols added in v0.1.13

func FitCols(cols, width int) int

FitCols reduces a requested column count until every column is at least MinTrackWidth wide, never dropping below a single column. A width below one cannot hold even a single track, so it also yields a single column.

func FitsScreenWidth

func FitsScreenWidth(screenWidth int) bool

FitsScreenWidth reports whether a terminal of this width can host the UI. Unknown widths (<= 0) are assumed to fit; below theme.MinScreenWidth render TooNarrow instead.

func FlexColCount

func FlexColCount(width, minWidth, maxCols int) int

FlexColCount returns how many equal-width tracks fit in width, given a minimum track width and a hard cap, clamped to [1, maxCols]. The requested minimum is itself floored at MinTrackWidth: a track narrower than that cannot hold a box, so asking for one yields fewer, wider columns instead.

func IndentLines added in v0.0.4

func IndentLines(s string, n int) string

IndentLines prefixes every line of s (including blank ones) with n spaces.

func Lines added in v0.1.6

func Lines(s string) []string

Lines splits s into display lines. Every trailing newline is dropped, so a block ending in "\n" yields no spurious empty last line; interior blank lines are preserved. Input is assumed to use "\n" endings, not CRLF.

func Overlay

func Overlay(bg, fg string, pos ...OverlayPos) string

Overlay draws fg on top of bg at the given anchor (Center when omitted). The covered strip of each background line is replaced — ANSI-aware, with the foreground padded to its block width so background text cannot bleed through. A foreground taller than the background extends the result downward rather than being clipped.

func PadLines

func PadLines(body string, rows int) string

PadLines pads body with trailing newlines until it spans rows display lines. It never trims: a body already at or over the budget is returned unchanged. rows <= 0 returns "".

func ScrollPanel

func ScrollPanel(title string, lines []string, rows, offset int) string

ScrollPanel is Frame.ScrollPanel on the default-width frame.

func ScrollableBody

func ScrollableBody(body string, rows int) string

ScrollableBody returns the part of body that ViewportLayout would scroll: the content above the sticky footer. A body with no footer scrolls whole and is returned as is; if the footer leaves no room to scroll it returns "".

func ScrollableRows

func ScrollableRows(body string, rows int) int

ScrollableRows returns how many of the given rows ViewportLayout would give the scrolling content once the sticky footer (and the separator line before it) is paid for. Callers use it to clamp scroll offsets.

func SplitStickyFooter

func SplitStickyFooter(body string) (content, footer string)

SplitStickyFooter splits body at its *last* blank line: everything after it is the sticky footer, everything before it the scrollable content. A body with no blank line has no footer.

func Spread

func Spread(left, right string, width int) string

Spread lays left and right on one line with the gap between them padded so the line is exactly width cells (theme.BodyWidth when width <= 0). When both sides cannot fit, the right side wins: left is truncated with an ellipsis first, and dropped entirely before right is ever shortened.

func SpreadBGIn added in v0.2.2

func SpreadBGIn(th theme.Theme, bg lipgloss.TerminalColor, left, right string, width int) string

SpreadBGIn is Spread with the gap painted in the given background color, for lines that sit on a filled strip (status bars, headers). The truncation ellipsis is styled to match the strip, dimmed with th.

func Stack

func Stack(sections ...string) string

Stack joins non-empty sections with a blank line between them; empty sections vanish rather than leaving double gaps.

func StackFit

func StackFit(tier Tier, sections ...Section) string

StackFit stacks the sections visible at the given tier (tier >= MinTier) with blank lines between them, like Stack.

func StackTight

func StackTight(sections ...string) string

StackTight joins non-empty sections with single newlines (no blank line between them).

func StackTightFit

func StackTightFit(tier Tier, sections ...Section) string

StackTightFit is StackFit joined with single newlines instead of blank lines.

func TooNarrowIn added in v0.2.2

func TooNarrowIn(t theme.Theme, screenWidth int) string

TooNarrowIn renders th's "terminal too narrow" notice, sized to the given width (or the minimum layout width when the width is unknown), showing the current and required column counts.

func ViewportContentRows

func ViewportContentRows(rows int) int

ViewportContentRows reports how many content rows Viewport shows for a given budget once the hint line and optional margin row are paid for — use it to clamp offsets consistently with Viewport's own windowing.

func ViewportLayout

func ViewportLayout(body string, rows, offset int) string

ViewportLayout scrolls body inside rows of height while keeping a sticky footer pinned to the bottom, hint lines styled with the built-in default theme. The footer is whatever follows the last blank line (see SplitStickyFooter); only the content above it scrolls with offset. If the footer alone fills the budget the content is dropped entirely, and rows <= 0 returns the body unscrolled.

Types

type Arranger added in v0.2.0

type Arranger interface {
	Arrange(f Frame, tier Tier, panes []Pane, focusedName string) string
}

Arranger positions and renders a set of panes into a single block. f is the full area available, tier filters panes by MinTier, and focusedName marks which interactive pane renders with a focused Frame. Implementations include SingleColumn, Grid, FlexColumns, FlexRows, and FlexSections.

type FlexBounds added in v0.2.1

type FlexBounds struct {
	MinWidth int
	MaxCols  int
}

FlexBounds is the shared track sizing for flex layouts: minimum track width and maximum column count. Zero values fall back to the Default* constants.

func (FlexBounds) Columns added in v0.2.1

func (b FlexBounds) Columns(width int) int

Columns reports how many tracks fit at the given width.

type FlexColumns

type FlexColumns struct {
	FlexBounds
}

FlexColumns is a responsive column-masonry layout: panes are distributed round-robin into N equal-width vertical stacks, where N grows with width. Columns keep a fixed width, so a pane never expands into an empty neighbour.

func (FlexColumns) Arrange

func (g FlexColumns) Arrange(f Frame, tier Tier, panes []Pane, focusedName string) string

Arrange implements Arranger: tier-visible panes are dealt round-robin into the column stacks, each column is stacked tightly, and all columns are composited side by side padded to the tallest column's height. It ignores Frame.Height and grows to content height.

type FlexRows

type FlexRows struct {
	FlexBounds
}

FlexRows is a responsive row-major layout: panes fill left-to-right into rows of up to N tracks (N grows with width). A row with fewer panes than N — most often the ragged final row — divides the full width among only the panes present, so a pane with no neighbour expands to fill the row. Each row is as tall as its tallest pane; shorter panes are padded to match.

func (FlexRows) Arrange

func (g FlexRows) Arrange(f Frame, tier Tier, panes []Pane, focusedName string) string

Arrange implements Arranger: tier-visible panes fill rows left to right, each row's width is split evenly among the panes actually in that row, and rows are stacked with blank lines between them. It ignores Frame.Height.

type FlexSections

type FlexSections struct {
	FlexBounds
}

FlexSections is FlexColumns applied per pane Group: panes sharing a Group value are flowed together under a titled section header (a rule line labeled with the group name), sections stacked in first-appearance order. Panes with an empty Group render without a header.

func (FlexSections) Arrange

func (g FlexSections) Arrange(f Frame, tier Tier, panes []Pane, focusedName string) string

Arrange implements Arranger by grouping tier-visible panes by Group and laying each group out with FlexColumns.

type Focusable

type Focusable struct {
	Name        string
	Interactive bool
}

Focusable names a candidate for the focus ring; only entries with Interactive set actually join it.

type Frame

type Frame struct {
	Width   int
	Height  int
	Focused bool
	// UI is the rendering scope (theme, keys, glyphs). Nil falls back to the
	// built-in defaults; derive new frames with WithWidth/Screen/WithUI so the
	// scope is never dropped.
	UI *ui.Scope
}

Frame is the rendering context handed to every layout helper: the width and height (in terminal cells) a block may occupy, and whether the block owns focus. A zero Height means "unconstrained"; helpers that need a height fall back to natural content height. Frame is a value type — Focus and WithHeight return modified copies.

Example
package main

import (
	"github.com/codyconfer/viewkit/layout"
)

func main() {
	f := layout.NewFrame(60)

	body := layout.Stack(
		f.Header("STATUS", "local"),
		f.Panel(
			"TOKENS",
			f.Row("balance", "12"),
			f.Row("rate", "0.8/s"),
		),
	)

	_ = layout.ViewportLayout(body, 12, 0)
}

func DefaultFrame

func DefaultFrame() Frame

DefaultFrame returns a Frame at the standard body width (theme.BodyWidth).

func DocumentFrame added in v0.2.0

func DocumentFrame() Frame

DocumentFrame returns a Frame at the standard document width (theme.BodyWidth) — the frame for scrollback/document output that is not sized to a live terminal.

func FrameFor added in v0.0.4

func FrameFor(w io.Writer) Frame

FrameFor sizes a Frame to the terminal behind w when w is a *os.File on a tty; anything else (pipes, buffers, size errors) gets DefaultFrame.

func NewFrame

func NewFrame(width int) Frame

NewFrame returns a Frame for the given body width. Non-positive widths fall back to theme.BodyWidth, and any width below theme.MinBodyWidth is clamped *up* to it — so boxes built on NewFrame widths can exceed the space a tiling layout allotted; see Frame.CellBox for the clamp-down alternative.

func ScreenFrame

func ScreenFrame(screenWidth int) Frame

ScreenFrame converts a full terminal width into a body Frame by subtracting theme.ScreenPaddingWidth; unknown widths get DefaultFrame. NewFrame's minimum-width clamp still applies.

func (Frame) BodyWidth

func (f Frame) BodyWidth() int

BodyWidth is the frame's width after NewFrame's clamping: non-positive widths become theme.BodyWidth and narrow ones are raised to theme.MinBodyWidth. Box, Panel, and TitledBox all size their bodies from it.

func (Frame) Box

func (f Frame) Box(lines ...string) string

Box renders lines inside the theme panel border at the frame's BodyWidth. Because BodyWidth clamps narrow frames *up* to theme.MinBodyWidth, a Box can be wider than f.Width; inside a tiling layout use Frame.CellBox instead, which clamps down to fit the cell. A focused frame uses the focus border style.

func (Frame) CellBox

func (f Frame) CellBox(title string, lines ...string) string

CellBox renders a bordered box that fills exactly f.Width columns: the border and padding cost 4 columns, so the body is f.Width-4. Unlike NewFrame, a cell narrower than theme.MinBodyWidth+4 clamps the body *down* rather than up, so the box never spills past the rect its layout gave it and never loses its right border to the compositor.

func (Frame) CellPanel

func (f Frame) CellPanel(title string, lines []string, offset int) string

CellPanel is CellBox with a scrolling body sized to f.Height.

func (Frame) CellTitledBox added in v0.1.14

func (f Frame) CellTitledBox(title string, lines ...string) string

CellTitledBox is TitledBox sized to fit inside f.Width rather than around it. TitledBox routes through Frame.BodyWidth, which clamps a narrow body *up* to theme.MinBodyWidth, so a titled pane needs theme.MinBodyWidth+4 columns before it stops spilling past the rect its layout gave it — MinTrackWidth alone is not enough. CellTitledBox clamps the body down instead, exactly as CellBox does, and so keeps its right border in any track.

func (Frame) CellTitledBoxIcon added in v0.1.14

func (f Frame) CellTitledBoxIcon(icon, title string, lines ...string) string

CellTitledBoxIcon is CellTitledBox with an icon before the title, clamped down to f.Width like the rest of the Cell* family.

func (Frame) Cursor added in v0.2.2

func (f Frame) Cursor(selected bool) string

Cursor returns the two-cell selection marker: "▸ " when selected, otherwise two spaces so unselected rows keep the same indent.

func (Frame) Fit

func (f Frame) Fit(s string) string

Fit truncates s to the frame's body width with an ellipsis.

func (Frame) Focus

func (f Frame) Focus() Frame

Focus returns a copy of the frame with Focused set.

func (Frame) Glyphs added in v0.2.2

func (f Frame) Glyphs() glyph.Set

Glyphs returns the scoped glyph set, or the default-mode set when unscoped.

func (Frame) Header

func (f Frame) Header(title string, detail ...string) string

Header renders a title line followed by a Rule. Detail parts are appended dim after a "·" separator; blank parts are skipped, and the whole line is truncated with an ellipsis at the rule's width.

func (Frame) HintLine

func (f Frame) HintLine(pairs ...keys.Hint) string

HintLine renders key hints as "key label" pairs separated by dim dots, wrapping onto additional lines whenever the next pair would push past the body width.

func (Frame) Panel

func (f Frame) Panel(title string, lines ...string) string

Panel is Box with a styled title as its first line (truncated to the body width). It shares Box's clamp-up behavior on narrow frames; the tiling-safe variant is Frame.CellBox / Frame.CellPanel.

func (Frame) Row

func (f Frame) Row(label, value string) string

Row renders a dim label on the left and value on the right, spread across the body width.

func (Frame) Rule

func (f Frame) Rule() string

Rule renders a dim horizontal rule spanning the body width plus the 4 columns of box border/padding, so it lines up with Box and Panel edges.

func (Frame) Scheme added in v0.2.2

func (f Frame) Scheme() keys.Scheme

Scheme returns the scoped key scheme, or the built-in default when unscoped.

func (Frame) Screen added in v0.2.2

func (f Frame) Screen() Frame

Screen returns a copy sized as a body frame for a full terminal of the frame's width (ScreenFrame rules), preserving the scope.

func (Frame) ScrollPanel

func (f Frame) ScrollPanel(title string, lines []string, rows, offset int) string

ScrollPanel renders a Panel showing a rows-high window of lines starting at offset. When lines overflow the window a dim "↕ a–b of n" footer line is appended inside the panel; offsets are clamped, never wrapped.

func (Frame) ScrollPanelWithPrefix

func (f Frame) ScrollPanelWithPrefix(title string, prefix, lines []string, rows, offset int) string

ScrollPanelWithPrefix is ScrollPanel with fixed prefix lines pinned above the scrolling window (they do not scroll and do not count against rows). With no lines at all, the panel shows just the prefix.

func (Frame) Selectable

func (f Frame) Selectable(label string, selected bool) string

Selectable renders a list row: Cursor marker plus the label, accent-styled when selected and truncated to leave room for the marker.

func (Frame) Spread

func (f Frame) Spread(left, right string) string

Spread is the package-level Spread at the frame's body width.

func (Frame) Theme added in v0.2.2

func (f Frame) Theme() theme.Theme

Theme returns the scoped theme, or the built-in default when unscoped.

func (Frame) TitledBox added in v0.0.4

func (f Frame) TitledBox(title string, lines ...string) string

TitledBox renders a rounded box with the title embedded in the top border. The body is f.BodyWidth() wide, so like Box it clamps narrow frames *up* to theme.MinBodyWidth and can overflow a tiling layout's rect — use Frame.CellTitledBox inside grids.

func (Frame) TitledBoxIcon added in v0.0.4

func (f Frame) TitledBoxIcon(icon, title string, lines ...string) string

TitledBoxIcon is TitledBox with an icon rendered before the title in the top border. It shares TitledBox's clamp-up behavior.

func (Frame) Viewport added in v0.2.2

func (f Frame) Viewport(body string, rows, offset int) string

Viewport shows a scrolled window of body within a rows budget. A body that fits is returned whole; otherwise the last row (plus, at rows >= 3, a blank margin row) is spent on a "▲▼ pgup/pgdn · a–b of n" hint, so the content window is ViewportContentRows(rows) tall. Offsets are clamped; rows < 1 returns "".

func (Frame) WithHeight

func (f Frame) WithHeight(h int) Frame

WithHeight returns a copy of the frame constrained to h rows.

func (Frame) WithUI added in v0.2.2

func (f Frame) WithUI(scope *ui.Scope) Frame

WithUI returns a copy of the frame carrying scope.

func (Frame) WithWidth added in v0.2.2

func (f Frame) WithWidth(width int) Frame

WithWidth returns a copy at the given body width (NewFrame clamping rules), preserving the scope.

type Grid

type Grid struct {
	Cols int
	Rows int
}

Grid is a tiling Arranger: the frame is divided into Cols equal-width column tracks and panes are placed by GridPos (or auto-flowed), then composited to fill the frame exactly. Rows is a minimum row count; the grid grows past it as panes need. Panes tiled into grid tracks should render with the CellBox / CellTitledBox family, which stay inside their rect — see MinTrackWidth.

func (Grid) Arrange

func (g Grid) Arrange(f Frame, tier Tier, panes []Pane, focusedName string) string

Arrange implements Arranger. Column count is reduced with FitCols so no track drops below MinTrackWidth (pinned panes then reflow via auto-flow); Slim panes give up width to their row-mates; and the result is composited to exactly f.Width x f.Height, truncating pane output that overruns its rect. A frame without a height (f.Height < 1) falls back to SingleColumn.

type GridPos

type GridPos struct {
	Col     int
	Row     int
	ColSpan int
	RowSpan int
}

GridPos pins a pane to grid coordinates. Col/Row are zero-based; spans below 1 count as 1, and out-of-range values are clamped into the grid. Panes without a Pos cascade into the next free block instead.

type LayoutFactory

type LayoutFactory func(params Params) (Arranger, error) //nolint:revive // name predates the lint rule; renaming would break callers

LayoutFactory builds an Arranger from spec parameters.

type OverlayPos

type OverlayPos struct {
	XFrac float64
	YFrac float64
}

OverlayPos anchors an overlay as fractions of the free space between the foreground and background blocks: 0 is the left/top edge, 1 the right/bottom, 0.5 centered.

type Pane

type Pane struct {
	Name        string
	Title       string
	Group       string
	Interactive bool
	MinTier     Tier
	Pos         *GridPos
	Slim        bool
	Render      func(Frame) string
}

Pane is one composable region of a Screen. Render is called with the Frame (width/height/focus) the Arranger allotted; MinTier hides the pane on screens shorter than its tier; Pos pins it to grid coordinates; Slim lets row-mates take width it does not need; Interactive panes with a Name join the focus Ring.

func (Pane) Focused added in v0.2.1

func (p Pane) Focused(name string) bool

Focused reports whether name selects this pane for focus.

type PaneFactory

type PaneFactory[Ctx any] func(ctx Ctx) (pane Pane, ok bool)

PaneFactory builds a Pane from the caller's context. Returning ok=false omits the pane from the screen (BuildScreen skips it silently).

type PaneInfo

type PaneInfo struct {
	Key   string
	Title string
}

PaneInfo is a registered pane's key and human-readable title, as returned by Registry.PaneKeys.

type PaneRef

type PaneRef struct {
	Key     string   `json:"key"`
	Pos     *GridPos `json:"pos,omitempty"`
	MinTier *Tier    `json:"minTier,omitempty"`
	Slim    bool     `json:"slim,omitempty"`
}

PaneRef names a registered pane in a ScreenSpec and optionally overrides the placement fields (Pos, MinTier, Slim) of the Pane its factory builds. Slim only sets the flag — a spec cannot clear a factory's Slim.

type Params

type Params map[string]any

Params carries layout options from a ScreenSpec (typically decoded JSON or YAML) into a LayoutFactory.

func (Params) Int

func (p Params) Int(key string, def int) int

Int returns the value under key as an int, accepting int, int64, float64 (truncated), and json.Number; missing keys and any other type return def.

type Registry

type Registry[Ctx any] struct {
	// contains filtered or unexported fields
}

Registry maps spec keys to pane and layout factories for BuildScreen. Ctx is whatever state pane factories need at build time. Use NewRegistry — it pre-registers the built-in layouts.

func NewRegistry

func NewRegistry[Ctx any]() *Registry[Ctx]

NewRegistry returns a Registry with the built-in layouts pre-registered: "single" (SingleColumn), "flex-columns", "flex-rows", "sections" (all honoring minWidth/maxCols params), and "grid" (cols/rows params).

func (*Registry[Ctx]) LayoutFn

func (r *Registry[Ctx]) LayoutFn(key string, f LayoutFactory) *Registry[Ctx]

LayoutFn registers a layout factory under key and returns the registry for chaining. Registering an existing key — including a built-in like "grid" — replaces it.

func (*Registry[Ctx]) LayoutKeys

func (r *Registry[Ctx]) LayoutKeys() []string

LayoutKeys lists registered layout keys, sorted alphabetically.

func (*Registry[Ctx]) Pane

func (r *Registry[Ctx]) Pane(key, title string, f PaneFactory[Ctx]) *Registry[Ctx]

Pane registers a pane factory under key and returns the registry for chaining. Registering an existing key overwrites the previous factory and title in place; the key keeps its original position in PaneKeys order.

func (*Registry[Ctx]) PaneKeys

func (r *Registry[Ctx]) PaneKeys() []PaneInfo

PaneKeys lists registered panes in first-registration order.

type Ring

type Ring []string

Ring is the ordered list of interactive pane names focus cycles through. Callers keep an integer index and use At/Step; both tolerate out-of-range indexes by clamping.

func NewRing

func NewRing(all ...Focusable) Ring

NewRing builds a Ring from the interactive entries, preserving order and skipping non-interactive ones.

func PaneRing

func PaneRing(panes []Pane) Ring

PaneRing builds the focus Ring for a pane set: only interactive panes are included, in declaration order.

func (Ring) At

func (r Ring) At(idx int) string

At returns the name at idx, clamping out-of-range indexes to the nearest end; an empty ring returns "".

func (Ring) Step

func (r Ring) Step(idx, delta int) int

Step returns the index delta positions from idx, wrapping around both ends of the ring (delta may be negative). An empty ring returns 0.

type Screen

type Screen struct {
	Layout Arranger
	Panes  []Pane
}

Screen pairs a pane set with the Arranger that lays it out. A nil Layout falls back to SingleColumn.

func BuildScreen

func BuildScreen[Ctx any](s ScreenSpec, ctx Ctx, r *Registry[Ctx]) (Screen, error)

BuildScreen resolves a ScreenSpec against the registry. Unknown layout or pane keys (and a nil registry) are errors, but a pane factory returning ok=false just omits that pane. Spec-level Pos/MinTier/Slim overrides are applied to each built pane.

func (Screen) Render

func (s Screen) Render(f Frame, tier Tier, focused string) string

Render arranges the screen's panes for the given frame and tier, focusing the interactive pane named focused. A nil Layout uses SingleColumn.

func (Screen) Ring

func (s Screen) Ring() Ring

Ring returns the focus ring over the screen's interactive panes.

type ScreenSpec

type ScreenSpec struct {
	Layout       string    `json:"layout"`
	LayoutParams Params    `json:"layoutParams,omitempty"`
	Panes        []PaneRef `json:"panes"`
}

ScreenSpec is the declarative, serializable description of a Screen: a layout key with its params plus the panes to place. BuildScreen resolves it against a Registry.

type ScrollState

type ScrollState struct {
	Offset int
}

ScrollState is a scroll offset (in lines) with clamped mutation helpers. Embed or hold it by value in a view and pass the current totals into Scroll and Reveal; the state itself does not know the content size.

func (*ScrollState) Reveal

func (s *ScrollState) Reveal(index, total, rows int)

Reveal adjusts the offset just enough to bring line index into the visible window, then clamps like Scroll. Lines already visible leave the offset untouched.

func (*ScrollState) Scroll

func (s *ScrollState) Scroll(delta, total, rows int)

Scroll moves the offset by delta lines and clamps it to [0, total-rows], where total is the line count and rows the visible window height.

type Section

type Section struct {
	Content string
	MinTier Tier
}

Section is a block of rendered content plus the minimum Tier at which it should appear; StackFit and StackTightFit drop sections below the tier.

type SingleColumn

type SingleColumn struct{}

SingleColumn is the simplest Arranger: every visible pane renders at the full frame width and the results are stacked vertically with blank lines between them. It ignores Frame.Height, Pos, and Slim.

func (SingleColumn) Arrange

func (SingleColumn) Arrange(f Frame, tier Tier, panes []Pane, focusedName string) string

Arrange implements Arranger by stacking tier-visible panes top to bottom.

type Surface added in v0.5.1

type Surface struct {
	Width int
	Style lipgloss.Style
}

Surface is a solid-background rendering context for inline panel content.

func NewSurface added in v0.5.1

func NewSurface(width int, background lipgloss.TerminalColor) Surface

NewSurface creates a background-filled surface at width terminal cells.

func (Surface) Gap added in v0.5.1

func (s Surface) Gap() string

Gap returns a background-filled blank line spanning the surface width.

func (Surface) Render added in v0.5.1

func (s Surface) Render(content string) string

Render paints every line, including trailing spaces, across the surface width.

type Tier

type Tier int

Tier buckets terminal height into three coarse size classes so views can drop optional content on short screens instead of measuring exact rows. Higher tiers include everything lower ones show.

const (
	TierShort Tier = iota
	TierMedium
	TierTall
)

The three height tiers, from most to least constrained. TierForHeight maps a raw terminal height onto one of these.

func TierForHeight

func TierForHeight(height int) Tier

TierForHeight maps a terminal height to its Tier using the theme's body height thresholds. Unknown (non-positive) heights land on TierMedium via BodyBudget's minimum-height fallback.

type TierRows

type TierRows struct{ Short, Medium, Tall int }

TierRows holds a per-tier row count for content that scales with screen height (for example, how many list rows to show).

func (TierRows) At

func (r TierRows) At(t Tier) int

At returns the row count for the given tier; unknown tiers fall back to Short.

Jump to

Keyboard shortcuts

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