Help us shape the future of Go! Take the 2026 Go Developer Survey

layout

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package layout decides where each region of the terminal interface goes for a given terminal size.

It is pure arithmetic, kept apart from the Bubble Tea model so that the parts most likely to be wrong at the edges — clamping, leftover rows, a terminal resized to almost nothing — can be tested directly rather than inferred from a rendered screen.

Index

Constants

View Source
const (

	// BorderlessBelow is the width under which even the detail's border goes,
	// and a dialog becomes a sheet: at under 60 columns, two columns of
	// box-drawing are text that does not fit.
	BorderlessBelow = 60
)

Fixed regions and the rail's sizing rules.

Variables

This section is empty.

Functions

func ComputeWithNotice

func ComputeWithNotice(terminal Terminal, rail Rail) (Layout, Box)

ComputeWithNotice is Compute with a row reserved for a notice above the footer: the notice takes the row the footer would have had, the footer stays at the true bottom, and the row comes out of the focused pane and the detail beside it alone, so every pane without focus keeps the lines it shows and the rail does not jump while a notice comes and goes. A caller reserves the row only where NoticeKeepsFocus holds. It returns the layout and the notice's box.

func NoticeKeepsFocus added in v0.7.0

func NoticeKeepsFocus(terminal Terminal, rail Rail) bool

NoticeKeepsFocus reports whether a notice can have a row of its own without taking the focused rail pane under the rows it had without one, down to focusedMinimum: where it would, the notice belongs in the footer's row.

Types

type Box

type Box struct {
	X, Y          int
	Width, Height int
}

Box is a rectangle on screen, in cells.

func (Box) Contains

func (b Box) Contains(column, row int) bool

Contains reports whether a cell falls inside the box.

type Layout

type Layout struct {
	Spine  Box
	Rail   []Box
	Detail Box
	Footer Box
}

Layout is where every region goes.

func Compute

func Compute(terminal Terminal, rail Rail) Layout

Compute lays out a terminal of the given size with the rail's panes stacked down its left.

func (Layout) Borderless

func (l Layout) Borderless() bool

Borderless reports a terminal too narrow to spend columns on a border.

func (Layout) Collapsed

func (l Layout) Collapsed() bool

Collapsed reports whether the rail was dropped for lack of width.

func (Layout) CompactSpine

func (l Layout) CompactSpine() bool

CompactSpine reports a terminal too short for the spine's labels.

func (Layout) Dialog added in v0.11.0

func (l Layout) Dialog(want Size) Box

Dialog is where a dialog that would like to be want goes: centered across the screen and in the upper third of the body between the spine and the footer, within DialogRoom, and at least dialogLeast columns wide. Below 60 columns there is no room to float, and it is a sheet over the whole body.

func (Layout) DialogRoom added in v0.11.0

func (l Layout) DialogRoom() Size

DialogRoom is the most a floating dialog may take, its frame included: the screen less a margin each side, and the body less two rows. A dialog sized to fit what it says measures it within this room.

func (Layout) RailAt

func (l Layout) RailAt(column, row int) (int, bool)

RailAt reports which rail pane a cell falls in.

func (Layout) Sheet added in v0.11.0

func (l Layout) Sheet() bool

Sheet reports a screen too narrow to float a dialog over, below 60 columns: a dialog there is a sheet over the whole body, unframed as the detail pane is, however narrow what it holds.

type Rail added in v0.9.0

type Rail struct {
	Panes, Focused int
}

Rail is how many panes the rail stacks, and which of them, counted from zero, has focus.

type Size added in v0.11.0

type Size struct {
	Width, Height int
}

Size is how big something would like to be, in cells.

type Terminal added in v0.9.0

type Terminal struct {
	Width, Height int
}

Terminal is the size of the screen being laid out, in cells.

Jump to

Keyboard shortcuts

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