layout

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 1 Imported by: 0 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 is pure geometry for one sampled terminal frame. Rendering, popup placement, modal scrolling, and selection coordinates all consume the same value so a resize cannot mix dimensions from different terminal-size reads.

Go port of Ruby's lib/tui/screen_layout.rb. It lives with the terminal primitives because both the frame renderer and the mouse hit map must agree on the same rectangles; nothing here knows about tasks or views.

Index

Constants

View Source
const (
	// FixedRows is the header plus the two blank rows that separate it and the
	// footer from the body. The frame itself is undrawn — see internal/tui's
	// render.go, whose geometry this port must agree with cell for cell.
	FixedRows = 3

	PanelRatio          = 0.40
	WidePanelRatio      = 0.58
	MinPanelWidth       = 28
	MinListWidth        = 8
	EditMinContentWidth = 32
	InlineContentWidth  = 48
	// EditPanelChromeRows are the right panel's title and divider.
	EditPanelChromeRows = 2
	// EditMinVisibleRows is the compact focused-field fallback.
	EditMinVisibleRows = 1
)

Variables

PanelModes is the promotion ladder, narrowest first.

Functions

func MinimumEditTerminalHeight

func MinimumEditTerminalHeight(footerRows int) int

MinimumEditTerminalHeight is the named zero-footer minimum. Every footer/help row consumes another terminal row before the panel title, divider, and focused fallback.

func MinimumEditTerminalWidth

func MinimumEditTerminalWidth() int

MinimumEditTerminalWidth is the narrowest terminal that can host the editor.

func VisibleRows

func VisibleRows[T any](l *Layout, rows []T) []T

VisibleRows returns the slice of rows inside the viewport.

Types

type Breakpoint

type Breakpoint string

Breakpoint describes how much room the panel has for editable content.

const (
	BelowMinimum Breakpoint = "below_minimum"
	Stacked      Breakpoint = "stacked"
	Inline       Breakpoint = "inline"
)

type FooterLine

type FooterLine struct {
	Text string
	Rule bool
}

FooterLine is one footer entry. A Rule line draws a divider instead of text.

func Rule

func Rule() FooterLine

Rule is the divider sentinel (Ruby's :rule symbol).

func Text

func Text(s string) FooterLine

Text builds an ordinary footer line.

type Layout

type Layout struct {
	Width, Height      int
	Footer             []FooterLine
	BodyHeight         int
	BodyWidth          int
	ListWidth          int
	PanelWidth         int
	PanelContentWidth  int
	ViewportOffset     int
	Selected           *int
	SelectedScreenRow  *int
	PanelMode          PanelMode
	RequestedPanelMode PanelMode
	EditContentHeight  int
	PanelOffset        int
	// contains filtered or unexported fields
}

Layout is the resolved geometry. All fields are read-only after construction.

func New

func New(opts Options) *Layout

New resolves a layout from the sampled terminal size.

func (*Layout) BodyOrigin

func (l *Layout) BodyOrigin() (int, int)

BodyOrigin is the (row, col) of the first body cell.

func (*Layout) BodyRows

func (l *Layout) BodyRows() Span

func (*Layout) ContentBreakpoint

func (l *Layout) ContentBreakpoint() Breakpoint

ContentBreakpoint classifies the panel's editable content width.

func (*Layout) EditablePanel

func (l *Layout) EditablePanel() bool

EditablePanel reports whether the panel has room for the task editor.

func (*Layout) Editing

func (l *Layout) Editing() bool

func (*Layout) FooterRows

func (l *Layout) FooterRows() Span

func (*Layout) FooterSize

func (l *Layout) FooterSize() int

func (*Layout) HasPanel

func (l *Layout) HasPanel() bool

func (*Layout) HeaderRow

func (l *Layout) HeaderRow() int

func (*Layout) ListCols

func (l *Layout) ListCols() Span

func (*Layout) ModalBoxSize

func (l *Layout) ModalBoxSize(modal Modal) (width, height int)

ModalBoxSize is the drawn box size for a modal, shared by the renderer and the hit map so a click and a glyph never disagree.

func (*Layout) PanelCols

func (l *Layout) PanelCols() Span

func (*Layout) PanelDividerCol

func (l *Layout) PanelDividerCol() int

PanelDividerCol is the column of the "│" between list and panel, or -1 when no panel is drawn.

func (*Layout) PlaceModal

func (l *Layout) PlaceModal(modal Modal) Modal

PlaceModal supplies the modal's stable anchor. The frame still draws the box.

func (*Layout) PlacePopup

func (l *Layout) PlacePopup(popup Popup, preferredCol int) Popup

PlacePopup positions a popup under (or above) the selected row, clamped into the body.

type Modal struct {
	Title string
	Lines []string
	Width int
	// Row and Col are meaningful only once Placed is true; PlaceModal sets all
	// three. An unplaced modal is centered by the renderer.
	Row, Col int
	Placed   bool
}

Modal is a centered box over the body. Width pins the box width; zero means "fit the content".

type Options

type Options struct {
	Width, Height int
	Footer        []FooterLine
	// Selected is the absolute index of the selected row; nil means no
	// selection.
	Selected    *int
	Panel       bool
	PanelMode   PanelMode
	PanelOffset int
	Editing     bool
}

Options describes one sampled frame.

type PanelMode

type PanelMode string

PanelMode names one of the right panel's width presets.

const (
	PanelCompact  PanelMode = "compact"
	PanelStandard PanelMode = "standard"
	PanelWide     PanelMode = "wide"
	PanelFocus    PanelMode = "focus"
)
type Popup struct {
	Lines    []string
	Row, Col int
}

Popup is an overlay placed in body coordinates.

type Span

type Span struct{ Begin, End int }

Span is a half-open range [Begin, End) over 0-based terminal cells, so a click and a painted glyph always agree on "row 2 is the first body row".

func (Span) Covers

func (s Span) Covers(v int) bool

Jump to

Keyboard shortcuts

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