workspace

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 4 Imported by: 1 module, 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 workspace implements a tab-referencing split tree. It owns geometry, not tab models or keyboard focus; callers supply the active tab identity.

Index

Constants

View Source
const (
	MinWidth  = 24
	MinHeight = 8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Arrangement

type Arrangement struct {
	Panes    []Pane
	Dividers []Rect
	Fits     bool
}

Arrangement uses virtual minimum-sized bounds when Fits is false. This lets callers navigate the whole layout while drawing only their focused pane.

type Axis

type Axis string

Axis names describe the arrangement, not the direction of the divider.

const (
	Columns Axis = "columns"
	Rows    Axis = "rows"
)

type Direction

type Direction int

Direction is a spatial focus/swap direction.

const (
	Left Direction = iota
	Down
	Up
	Right
)

type Layout

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

Layout's zero value is an empty workspace. It deliberately has no active-tab field: the tab registry remains the single source of truth for activation.

func Restore

func Restore(state State, refs map[string]string) (layout Layout, focus string, repaired bool)

Restore validates and copies a serialized tree, pruning missing/duplicate tab references and collapsing empty branches. It never changes the caller's tabs. Cyclic/aliased node graphs are pruned without imposing a pane/depth cap. Version 1 binary splits are migrated to sibling containers with the same ratio.

func (Layout) Arrange

func (l Layout) Arrange(width, height int) Arrangement

Arrange allocates every cell exactly once, including one-cell dividers. Terminal resizing never rewrites preferred proportions.

func (Layout) CanSplit

func (l Layout) CanSplit(target string, axis Axis, width, height int) error

CanSplit checks a prospective split before asking the user to select a tab.

func (Layout) Contains

func (l Layout) Contains(tab string) bool

func (Layout) Count

func (l Layout) Count() int

func (Layout) Cycle

func (l Layout) Cycle(tab string, step, width, height int) string

func (Layout) First

func (l Layout) First() string

func (*Layout) Move

func (l *Layout) Move(tab string, direction Direction, width, height int) bool

Move is i3-like directional movement. A pane first swaps contents with its nearest neighbour. At the edge of a nested container it moves one level up the tree: it leaves its container and becomes a sibling of that container in the container above, on the requested side.

At the root there is no container above, so the pane cannot lift. There the previous re-dock is kept: the rest of the layout becomes one half of a new root split and the pane the other half, which is how a row becomes a stack (or the reverse). i3 itself refuses that move; changing the root's orientation is worth keeping.

func (Layout) Neighbour

func (l Layout) Neighbour(tab string, direction Direction, width, height int) string

Neighbour prefers the closest edge sharing the requested direction, then the closest perpendicular centre. Reading order is the deterministic tie-breaker.

func (Layout) PaneNumber

func (l Layout) PaneNumber(tab string) int

PaneNumber returns the 1-based tree/reading order index used by both tab badges and pane headers, or 0 when the tab is not assigned.

func (Layout) PaneOrder

func (l Layout) PaneOrder() []string

PaneOrder returns assigned tabs in the same tree order as PaneNumber/Arrange.

func (*Layout) Remove

func (l *Layout) Remove(tab string) string

Remove drops the pane and collapses a container that is left with one child. It returns the tab that should take focus, which the caller uses only when it removed the focused pane.

func (*Layout) Resize

func (l *Layout) Resize(tab string, axis Axis, steps, width, height int) bool

Resize moves the divider next to the focused pane by five-percent steps. Positive steps grow the focused child, even when it is not the first child of the container. It edits the deepest matching container on the pane's path.

func (Layout) Revision

func (l Layout) Revision() uint64

func (*Layout) Select

func (l *Layout) Select(target, tab string) bool

Select assigns an unassigned tab to the target pane, or creates the initial pane. An already assigned tab is left alone; its activation is the caller's job.

func (Layout) Snapshot

func (l Layout) Snapshot(focus string, refs map[string]string) State

func (*Layout) Split

func (l *Layout) Split(target, tab string, axis Axis, width, height int) error

Split is atomic, including fit validation. It never creates an empty pane. A pane whose container already splits along axis joins it as an equal sibling (i3's container list); otherwise the target is wrapped in a new container.

func (Layout) SplitAxis

func (l Layout) SplitAxis(tab string) Axis

SplitAxis reports the axis a new pane inherits from the layout: the focused pane's container orientation, or Columns for a pane that is alone.

func (*Layout) Swap

func (l *Layout) Swap(tab string, direction Direction, width, height int) bool

type Node

type Node struct {
	Tab string `json:"tab,omitempty"`

	Axis     Axis    `json:"axis,omitempty"`
	Children []*Node `json:"children,omitempty"`
	Weights  []int   `json:"weights,omitempty"`

	// Deprecated: version 1 layout fields, decode-only.
	Ratio  int   `json:"ratio,omitempty"`
	First  *Node `json:"first,omitempty"`
	Second *Node `json:"second,omitempty"`
}

Node is a serialized tree node: either a leaf (Tab) or a container (Axis with Children, one weight per child). Like i3, a container is a list of siblings, so adding a pane next to an existing one never deepens the tree.

Ratio, First and Second are the version 1 binary-split fields. They are only read to migrate old sessions and are never written.

type Pane

type Pane struct {
	Tab string
	Rect
}

type Rect

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

Rect is a terminal-cell rectangle with an exclusive right and bottom edge.

func (Rect) Contains

func (r Rect) Contains(x, y int) bool

type State

type State struct {
	Version int    `json:"version"`
	Root    *Node  `json:"root"`
	Focus   string `json:"focus"`
}

State refers to the caller's serialized tab records, not ephemeral UI IDs. Unknown versions are discarded by Restore without affecting those records.

Jump to

Keyboard shortcuts

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