tabs

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 6 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 tabs is a content-neutral ordered tab group and strip layout. Hosts own keys, labels, and values; this package does not know about files, issues, panes, or workspaces.

Index

Constants

View Source
const MaxPathLabel = 24

MaxPathLabel is the longest file-path label a tab will draw even when leftover width would let it grow. Paths past this are left-truncated so the filename stays visible.

View Source
const MinBudget = 10

MinBudget is the floor for one tab's column share, chrome and the per-tab close control included.

Variables

This section is empty.

Functions

func FitEnd added in v1.3.0

func FitEnd(text string, maxWidth int) string

FitEnd end-truncates text so a leading identifier stays visible.

func FitEndLabel added in v1.3.0

func FitEndLabel(text string, _, _, maxWidth int, _ bool) string

FitEndLabel is the FitLabel form of FitEnd.

func FitPath added in v1.3.0

func FitPath(path string, maxWidth int) string

FitPath left-truncates a file path so the filename stays visible. Cuts prefer a slash, producing labels like "…/dir/file.go". maxWidth is also clamped to MaxPathLabel so a lone tab cannot dominate the strip.

func FitPathLabel added in v1.3.0

func FitPathLabel(text string, _, _, maxWidth int, _ bool) string

FitPathLabel is the FitLabel form of FitPath.

func VisibleRange

func VisibleRange(widths []int, active, maxWidth int) (start, end int, showLeft, showRight bool)

VisibleRange is the inclusive [start, end] window of tabs that fit in maxWidth given their rendered widths, keeping the active tab visible. showLeft and showRight are the overflow markers for tabs outside the window.

Types

type CloseHover added in v1.3.0

type CloseHover struct {
	LeafID int
	Index  int
	On     bool
}

CloseHover is the per-tab × the pointer is over. LeafID is 0 on surfaces that draw a single strip; the zero value means no × is hovered, so a surface that never sets one renders exactly as before.

func CloseHoverAt added in v1.3.0

func CloseHoverAt(leafID, index int) CloseHover

CloseHoverAt names one leaf's tab.

func (CloseHover) Index0For added in v1.3.0

func (h CloseHover) Index0For() int

Index0For is IndexFor for a surface that draws one strip and tracks no leaf.

func (CloseHover) IndexFor added in v1.3.0

func (h CloseHover) IndexFor(leafID int) int

IndexFor is the hovered tab index within leafID's strip, or -1 when the pointer is somewhere else. Hosts pass the result straight to HoverClose.

type CloseResult

type CloseResult[T any] struct {
	Removed       []Item[T]
	ActiveRemoved bool
	Empty         bool
}

CloseResult tells a host what CloseMatching removed so it can clean values and decide whether to load the survivor. The group does not know about tmux, file deletion, or preview reset.

type FitLabel

type FitLabel func(text string, index, total, maxWidth int, active bool) string

FitLabel shortens a tab's text so the rendered pill fits in maxWidth. maxWidth is the label column budget (chrome and close already reserved). The function returns label text, not the painted tab.

type Group

type Group[T any] struct {
	Items  []Item[T]
	Active int
}

Group is an ordered tab set with one active index.

func (Group[T]) ActiveItem

func (g Group[T]) ActiveItem() (Item[T], bool)

ActiveItem is the selected tab, or false when the group is empty or Active is out of range.

func (*Group[T]) Append

func (g *Group[T]) Append(key string, value T)

Append always adds a tab and selects it.

func (*Group[T]) AppendItem

func (g *Group[T]) AppendItem(item Item[T])

AppendItem always adds item and selects it.

func (*Group[T]) CloseActive

func (g *Group[T]) CloseActive() CloseResult[T]

CloseActive removes the selected tab. An empty group leaves Active at 0.

func (*Group[T]) CloseAt

func (g *Group[T]) CloseAt(index int) CloseResult[T]

CloseAt removes the tab at index. Out of range is a no-op.

func (*Group[T]) CloseMatching

func (g *Group[T]) CloseMatching(pred func(Item[T]) bool) CloseResult[T]

CloseMatching removes every item for which pred is true. Removals before the original Active are counted once, then Active is clamped.

func (*Group[T]) Cycle

func (g *Group[T]) Cycle(delta int)

Cycle moves Active by delta, wrapping at the ends. Fewer than two tabs is a no-op.

func (Group[T]) Find

func (g Group[T]) Find(key string) int

Find returns the first item whose Key equals key, or -1.

func (*Group[T]) OpenOrFocus

func (g *Group[T]) OpenOrFocus(key string, value T) (index int, created bool)

OpenOrFocus selects the first item with key, or appends value and selects it.

func (*Group[T]) Select

func (g *Group[T]) Select(i int)

Select makes i the active tab. Out of range is a no-op.

func (Group[T]) VisibleRange

func (g Group[T]) VisibleRange(widths []int, maxWidth int) (start, end int, showLeft, showRight bool)

VisibleRange is the overflow window for this group, keeping Active on screen.

type Hit

type Hit struct {
	Index    int
	Col      int
	Width    int
	Rendered string
	CloseCol int
	CloseW   int
}

Hit is a drawn tab's click target. Col is relative to the strip's first column; Width is the rendered pill. CloseCol/CloseW are the × control on the pill's right edge; CloseW is 0 when the tab was too narrow to hold one.

type Item

type Item[T any] struct {
	Key     string
	Value   T
	Preview bool
}

Item is one open tab. Keys need not be unique; Find returns the first match.

type Label

type Label struct {
	Text    string
	Preview bool
}

Label is the text a host wants drawn on one tab.

type Strip

type Strip struct {
	Row  string
	Tabs []Hit
}

Strip is the header row: only tabs, packed left to right.

func LayoutStrip

func LayoutStrip(labels []Label, active, width int, focused bool, fit FitLabel) Strip

LayoutStrip paints labels left to right with overflow markers. Leftover width goes to the active tab. Hits describe the tabs actually painted.

func (Strip) HoverClose added in v1.3.0

func (s Strip) HoverClose(index int) Strip

HoverClose repaints one tab's × as hovered. It rewrites only the cells the × already occupies, so the row keeps its width and every Hit — including the close target the pointer is inside — stays where it was registered. An index that is not painted, or a tab too narrow to carry a ×, is a no-op.

func (Strip) RegisterHits added in v1.3.0

func (s Strip) RegisterHits(add func(col, width, index int, close bool))

RegisterHits calls add once for each painted tab, then once for each tab's close control. Close is registered second so it wins the cells it occupies, the same order paneframe uses for the leaf-header X.

Jump to

Keyboard shortcuts

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