layout

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 0 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 keeps SSHYard's workspace: tabs, each a tree of split panes, each pane showing one item. An item is of a kind: a terminal session, a files (SFTP) browser, an editor of a remote file, or an AI assistant. All are panes alike, so any of them can sit in any split cell, be dragged onto another pane's edge, be focused and closed. An item lives in exactly one pane; moving it (by drag and drop) takes it out of its old pane. Item IDs are unique across kinds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Axis

type Axis int

Axis is how a split lays its two children out.

const (
	// Row puts the children left and right.
	Row Axis = iota
	// Column puts the children top and bottom.
	Column
)

type Edge

type Edge int

Edge is where a dropped item lands relative to a pane.

const (
	Center Edge = iota // swap into the pane
	Left
	Right
	Top
	Bottom
)

type Item

type Item struct {
	Kind Kind
	ID   int
}

Item is what a pane shows: an ID of the app's and its kind.

type Kind

type Kind int

Kind is what a pane shows.

const (
	// Terminal is a terminal session.
	Terminal Kind = iota
	// Files is a files (SFTP) browser.
	Files
	// Editor edits a remote file.
	Editor
	// AI is an assistant bound to one host. It does not open a connection.
	AI
)

func (Kind) String

func (k Kind) String() string

type Node

type Node struct {
	ID    int
	Item  Item
	Axis  Axis
	Ratio float32 // share of A, 0 to 1
	A, B  *Node
}

Node is a pane (Item.ID != 0, no children) or a split (A and B).

func (*Node) Leaf

func (n *Node) Leaf() bool

Leaf reports whether n is a pane.

type Tab

type Tab struct {
	ID    int
	Root  *Node
	Focus int // the focused pane
	// Title is the name the user gave the tab, "" for its host's.
	Title string
}

Tab is one tab of the workspace.

func (*Tab) Count

func (t *Tab) Count(k Kind) int

Count counts the tab's panes of a kind.

func (*Tab) Focused

func (t *Tab) Focused() Item

Focused is the item of the focused pane.

func (*Tab) Items

func (t *Tab) Items() []Item

Items lists the tab's items in reading order.

func (*Tab) Pane

func (t *Tab) Pane(id int) *Node

Pane finds a pane of the tab.

func (*Tab) Panes

func (t *Tab) Panes() []*Node

Panes lists the tab's panes in reading order.

type Workspace

type Workspace struct {
	Tabs   []*Tab
	Active int // index into Tabs, -1 when empty
	// contains filtered or unexported fields
}

Workspace is the set of tabs.

func New

func New() *Workspace

New makes an empty workspace.

func (*Workspace) Activate

func (w *Workspace) Activate(id int) bool

Activate shows the tab and focuses the pane with the item.

func (*Workspace) ActiveTab

func (w *Workspace) ActiveTab() *Tab

ActiveTab is the shown tab, or nil.

func (*Workspace) AddTab

func (w *Workspace) AddTab(root *Node, focus int)

AddTab appends a tab whose root the caller built with FreshID, and shows it. focus is a pane id in root; an unknown focus lands on the first pane.

func (*Workspace) Close

func (w *Workspace) Close(id int) bool

Close removes the pane showing an item.

func (*Workspace) CloseTab

func (w *Workspace) CloseTab(tabID int) []Item

CloseTab removes a whole tab and returns its items.

func (*Workspace) Detach

func (w *Workspace) Detach(id int) bool

Detach moves an item out to a tab of its own.

func (*Workspace) FreshID

func (w *Workspace) FreshID() int

FreshID is a new id for a node a caller builds itself (layout restore).

func (*Workspace) Items

func (w *Workspace) Items() []Item

Items lists every item of the workspace.

func (*Workspace) Locate

func (w *Workspace) Locate(id int) (*Tab, *Node)

Locate finds the tab and pane that show an item, by its ID.

func (*Workspace) Move

func (w *Workspace) Move(id, targetPane int, edge Edge) bool

Move drops an item on a pane: at the Center the two items swap places; at an edge the target pane splits and the item takes the new half. The item leaves its old pane, and a tab left empty closes. Kinds mix freely.

func (*Workspace) Open

func (w *Workspace) Open(item Item) *Tab

Open shows an item in a new tab and makes it active.

func (*Workspace) Place

func (w *Workspace) Place(item Item, targetPane int, edge Edge) bool

Place puts an item that is in no pane yet on a pane: at an edge the pane splits and the item takes the new half; at the Center it takes the pane, and the item it showed moves out to a tab of its own, so that nothing is lost.

func (*Workspace) Replace

func (w *Workspace) Replace(old int, item Item) bool

Replace shows item, which is in no pane yet, in the pane showing the item with ID old, which leaves the workspace. The pane is focused.

func (*Workspace) SplitFocused

func (w *Workspace) SplitFocused(axis Axis, item Item) *Node

SplitFocused splits the active tab's focused pane, showing item in the new pane (right of or below it), and focuses the new pane. With no tab it opens one.

func (*Workspace) TabOf

func (w *Workspace) TabOf(pane int) *Tab

TabOf is the tab with the pane of node ID pane, nil for none.

Jump to

Keyboard shortcuts

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